Section 24.20. Boolean: support for boolean values


24.20. Boolean: support for boolean values

ECMAScript v1: Object Boolean

24.20.1. Constructor

 new Boolean(value) // Constructor function Boolean(value)     // Conversion function 

24.20.1.1. Arguments

value

The value to be held by the Boolean object or to be converted to a boolean value.

24.20.1.2. Returns

When invoked as a constructor with the new operator, Boolean( ) converts its argument to a boolean value and returns a Boolean object that contains that value. When invoked as a function, without the new operator, Boolean( ) simply converts its argument to a primitive boolean value and returns that value.

The values 0, NaN, null, the empty string "", and the undefined value are all converted to false. All other primitive values, except false (but including the string "false"), and all objects and arrays are converted to TRue.

24.20.2. Methods


toString( )

Returns "true" or "false", depending on the boolean value represented by the Boolean object.


valueOf( )

Returns the primitive boolean value contained in the Boolean object.

24.20.3. Description

Boolean values are a fundamental datatype in JavaScript. The Boolean object is an object wrapper around the boolean value. This Boolean object type exists primarily to provide a toString( ) method to convert boolean values to strings. When the toString( ) method is invoked to convert a boolean value to a string (and it is often invoked implicitly by JavaScript), JavaScript internally converts the boolean value to a transient Boolean object, on which the method can be invoked.

24.20.4. See Also

Object




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

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