JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Boolean Object

Name

Boolean Object---support for Boolean values

Availability

Navigator 3.0

Constructor

new Boolean(value)

Arguments

value

The value to be held by the Boolean object. This argument will be converted to a Boolean value, if necessary. The values 0, null and the empty string "" are all converted to false. All other values, including the string "false", are converted to true.

Returns

The newly created Boolean object.

Methods

toString()

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

valueOf()

Return the Boolean value represented by the Boolean object.

Description

Boolean values are a fundamental data type in JavaScript. The Boolean object is an object wrapper around the Boolean value. This Boolean object type exists solely 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.

You can create Boolean objects that are not transient by calling the Boolean() constructor method. One reason you might occasionally want to do so is to force a conversion of another value to a Boolean value. Having created a Boolean object, you can use it freely wherever JavaScript expects a primitive Boolean value--JavaScript will automatically invoke the valueOf() method to return the primitive value of the Boolean object.

See Also

"Object"


Previous Home Next
blur() Book Index Boolean.prototype

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
This HTML Help has been published using the chm2web software.