by using the Boolean() function. The Boolean() function c an either be invoked
as a constructor (with the new operator) or as a conversion function (without the new
operator). In both cases its first step is to convert value to a b oolean value, where the
values 0, NaN, null , undefined, fal se, and the empty string "" are all converted
to false. All other values (primitive and object)—including the string "false"—
are converted to true. After the conversion, the Bo olean() constructor returns a
Boolean object containing the converted value. The Boolea n() conversion function,
however, simply returns a primitive b oolean value.
Methods
toString()
Syntax:
boolean .toString()
Returns a string representation of the value stored in boolean , which can be either
"true" or "false". The method ca n also be invoked on a primitive boolean value, in
which case JavaScript creates a temporary wrapper Boolean object in or der to be able
to call the method. However, this is rarely needed in practice b ecause JavaScript calls
the toString() method automatically when the automatic conversion rules demand
that a boolean value be converted to a string (e.g., in a string con catenation with the
concatenation operator (+ )).
Examples:
var b = true;
var B = new Boolean(true);
B.toString() //Returns "true"
//In the following two examples JavaScript automatically creates
//temporary wrapper objects to be able to call toString():
b.toString() //Returns "true"
false.toString() //Returns "false"
valueOf()
Syntax:
boolean .valueOf()
Returns the primitive boole an value stored in the object.
E.5 console (Client-Side JavaScript)
Modern browsers have integrate d a debugging console (e.g., the JavaScript Console
in Google Chrome , or the Browser Console in Fir efox, both accessible through the
380 JavaScript Reference