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);
document.write(a); 

var a = new Boolean(0);
document.write(a); 

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

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

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

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

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

JavaScript also says false the values of following keywords:

© 2008-2012 Xul.fr