Source @ github

Boolean

Boolean — The Boolean object is an object wrapper for a boolean value.

Description

new Boolean(mixed bool)

Parameters

Name Description Type Default Optional
bool mixed No

Examples

Example #1 – boolean example

When creating a boolean object, you have to check the value of the object. The object itself will always return true.

var b = new Boolean(true); // Create a new boolean object. if (b.valueOf()) { console.log('The value of b is true.'); }

This however does not apply when working with boolean primitives.

var b = true; // Create a new boolean primitive. if (b) { console.log('The value of b is true.'); }
Example #2 – boolean example

Convert a non-boolean value to a boolean primitive.

bool = Boolean('false'); console.log(bool); // Will return true. bool = Boolean(0); console.log(bool); // Will return false.

See also

  • Primitives

External references