The Boolean type is the reference type that corresponds to the Boolean value. To create an object, a Boolean constructor is used with TRUE or FALSE values passed in.

var boolObject = new Boolean(true);

The main difference between here mentioned Boolean primitive and previously learnt Boolean reference type is in fact that primitive Boolean objects when evaluated, do not return their values, but rather themselves. The example below shows a result of such an evaluation:

var falseObject = new Boolean(false); // value is FALSE

var evaluate = falseObject && true;

alert(evaluate); // result is FALSE

We can see that the alert statement returns FALSE and not TRUE which would be a logical Boolean operation. That is because it evaluates variable falseObject as an object, and not object's value (FALSE).

 

›› go to examples ››