Boolean, the object and boolean values in JavaScript

The object may contain two boolean values, true and false. In addition there is the JavaScript keywords true and false, which can be compared to the result of a conditional expression. They are semantically different things even though they have the same effects in operations.

A Boolean object may be created with the following syntax:

var b = new Boolean(value) 

The value being either 1 or true, or 0 or false.

Some examples of use of boolean numbers, with results displayed in the page, under the code...

var a = new Boolean(1);

var a = new Boolean(0);

Any number different of 0 is true.
var a = new Boolean(5);

A string is true.
var a = new Boolean("text");

Even if it is empty...
var a = new Boolean("");

The true keyword has the boolean value true.
var a = new Boolean(true);

The false keyword has the boolean value false.
var a = new Boolean(false);

JavaScript also says false the values of following keywords:

© 2008-2012