Boolean
object is an object wrapper for a boolean value.
Core object | |
Implemented in | Navigator 3.0, LiveWire 1.0 |
Created by
The Boolean
constructor:
new Boolean(value)
Parameters
Description
Use a Boolean
object when you need to convert a non-boolean value to a boolean value. You can use the Boolean
object any place JavaScript expects a primitive boolean value. JavaScript returns the primitive value of the Boolean
object by automatically invoking the valueOf
method.
| Defines a property that is shared by all Boolean objects. |
| Returns a string representing the specified object. |
Examples
The following examples create Boolean
objects with an initial value of false:
bNoParam = new Boolean()
The following examples create
bZero = new Boolean(0)
bNull = new Boolean(null)
bEmptyString = new Boolean("")
bfalse = new Boolean(false)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") Properties
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 | Navigator 3.0, LiveWire 1.0 |
Methods
toString
Returns a string representing the specified object.
Method of |
Boolean
|
Implemented in | Navigator 3.0, LiveWire 1.0 |
Syntax
toString()
Parameters
None.
Description
Every object has a toString
method that is automatically called when it is to be represented as a text value or when an object is referred to in a string concatenation.
You can use toString
within your own code to convert an object into a string, and you can create your own function to be called in place of the default toString
method.
For Boolean
objects and values, the built-in toString
method returns "true"
or "false"
depending on the value of the boolean object. In the following code, flag.toString
returns "true"
.
flag = new Boolean(true)
For information on defining your own
document.write("flag.toString() is " + flag.toString() + "<BR>")toString
method, see the Object.toString
method.
Last Updated: 10/31/97 16:00:33