Table of Contents | Previous | Next | Index


Boolean

The Boolean object is an object wrapper for a boolean value.

Core object

Implemented in

JavaScript 1.1, NES 2.0

ECMA version

ECMA-262

Created by

The Boolean constructor:

new Boolean(value)

Parameters

value

The initial value of the Boolean object. The value is converted to a boolean value, if necessary. If value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false. All other values, including any object or the string "false", create an object with an initial value of true.

Description

When a Boolean object is used as the condition in a conditional test, JavaScript returns the value of the Boolean object. For example, a Boolean object whose value is false is treated as the primitive value false, and a Boolean object whose value is true is treated as the primitive value true in conditional tests. If the Boolean object is a false object, the conditional statement evaluates to false.

Property Summary

Property Description
constructor

Specifies the function that creates an object's prototype.

prototype

Defines a property that is shared by all Boolean objects.

Method Summary

Method Description
toString

Returns a string representing the specified object. Overrides the Object.toString method.

valueOf

Returns the primitive value of a Boolean object. Overrides the Object.valueOf method.

In addition, this object inherits the watch and unwatch methods from Object.

Examples

The following examples create Boolean objects with an initial value of false:

bNoParam = new Boolean()
bZero = new Boolean(0)
bNull = new Boolean(null)
bEmptyString = new Boolean("")
bfalse = new Boolean(false)
The following examples create Boolean objects with an initial value of true:

btrue = new Boolean(true)
btrueString = new Boolean("true")
bfalseString = new Boolean("false")
bSuLin = new Boolean("Su Lin")

constructor

Specifies the function that creates an object's prototype. Note that the value of this property is a reference to the function itself, not a string containing the function's name.

Property of

Boolean

Implemented in

JavaScript 1.1, NES 2.0

ECMA version

ECMA-262

Description

See Object.constructor.


prototype

Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class. For information on prototypes, see Function.prototype.

Property of

Boolean

Implemented in

JavaScript 1.1, NES 2.0

ECMA version

ECMA-262


toString

Returns a string representing the specified Boolean object.

Method of

Boolean

Implemented in

JavaScript 1.1, NES 2.0

ECMA version

ECMA-262

Syntax

toString()

Parameters

None.

Description

The Boolean object overrides the toString method of the Object object; it does not inherit Object.toString. For Boolean objects, the toString method returns a string representation of the object.

JavaScript calls the toString method automatically when a Boolean is to be represented as a text value or when a Boolean is referred to in a string concatenation.

For Boolean objects and values, the built-in toString method returns the string "true" or "false" depending on the value of the boolean object. In the following code, flag.toString returns "true".

var flag = new Boolean(true)
var myVar=flag.toString()

See also

Object.toString


valueOf

Returns the primitive value of a Boolean object.

Method of

Boolean

Implemented in

JavaScript 1.1

ECMA version

ECMA-262

Syntax

valueOf()

Parameters

None

Description

The valueOf method of Boolean returns the primitive value of a Boolean object or literal Boolean as a Boolean data type.

This method is usually called internally by JavaScript and not explicitly in code.

Examples

x = new Boolean();
myVar=x.valueOf()      //assigns false to myVar

See also

Object.valueOf


Table of Contents | Previous | Next | Index

Last Updated: 11/13/98 10:22:49

Copyright © 1998 Netscape Communications Corporation

Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use