The boolean data type is a primitive data type that can hold one of two values: true or false. Boolean values are used to represent truth values or logical values.
JavaScript provides a Boolean object as a wrapper for the two boolean values. The new Boolean() constructor creates a Boolean object:
var bool1 = new Boolean([value]);
The value passed as a parameter may be of any type. It will be converted to a boolean value, if necessary.
Any value can be interpreted as a boolean value. Values such as undefined, null, false, 0, NaN and empty strings evaluate to false. Passing any other value to the new Boolean() constructor creates an object with the value of true.
The Boolean() global function evaluates the truth value of a given value:
var bool2 = Boolean(value);
As with the constructor, the argument may be of any type. The Boolean() function returns a boolean primitive, either true or false.
constructorBoolean objectprototypetoString()Boolean object, either "true" or "false"valueOf()Boolean object, either true or falseIf you see a typo, want to make a suggestion or have anything in particular you'd like to know more about, please drop us an e-mail at hello at diveintojavascript dot com.
Copyright © 2010-2011 Dive Into JavaScript