Boolean


Boolean is the built-in object corresponding to the primitive Boolean data type. This object is extremely simple. It has no interesting properties of its own. It inherits all of its properties and methods from the generic Object . So it has toSource() , toString() , and valueOf() . Out of these, maybe the only method of practical use is the toString() method, which returns the string true if the value is true or false otherwise . The constructor takes an optional Boolean value indicating its initial value:

 var boolData = new Boolean(true); 

However if you don t set a value with the constructor, it will be false by default.

 var anotherBool = new Boolean(); // set to false 

Because of some subtleties in JavaScript s type conversion rules, it is almost always preferable to use primitive Boolean values rather than Boolean objects.




JavaScript 2.0
JavaScript: The Complete Reference, Second Edition
ISBN: 0072253576
EAN: 2147483647
Year: 2004
Pages: 209

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net