All Objects
Object.constructor
OBJECT: Boolean
new
Boolean
(value)
The
Boolean
object is an object wrapper for a Boolean value and is constructed with the above Boolean constructor. If there is no initial value or if it is 0, -0,
null
,
false
,
NaN
,
undefined
, or the empty string (""), the initial value is
false
. Otherwise, even with the string "false", it is true. So, all the following objects have an initial value of
false
:
x = new Boolean()
x = new Boolean(0)
x = new Boolean(-0)
x = new Boolean(null)
x = new Boolean(false)
x = new Boolean(NaN)
x = new Boolean(undefined)
x = new Boolean("")
...whereas in the following examples the Boolean object 'x' has an initial value of
true
:
myBool = new Boolean(false)
x = new Boolean(myBool)
x = new Boolean("false")
Any
Boolean
object that is passed to a conditional statement (except those with an initial value of
null
or
undefined
) evaluates to true. So, for instance, the conditional statement in the following code evaluates to
true
.
Code:
x = new Boolean(false)
if(x)
However, this does not apply to Boolean primitives, and the conditional statement in the following code evaluates to
false
.
Code:
x = false
if(x)
NOTE:
In JavaScript 1.3 and later versions, don't use a
Boolean
object instead of a Boolean primitive, nor should you use a
Boolean
object to convert a non-Boolean value to a Boolean one. To do so use
Boolean
as a function. For example, the following converts the expression 'a+b' to a Boolean value:
Code:
x = Boolean(a+b)
PROPERTIES
constructor property
This property specifies the function that created the object's prototype. See also the
Object.constructor
property.
Syntax:
object.
constructor
prototype property
This property represents the prototype for this object and allows you to add methods and properties of your own. See also the
Function.prototype
property.
Syntax:
object.
prototype
METHODS
toSource method
This method, which is usually called internally by JavaScript, returns a string representing the source code of the object. It overrides the
Object.toSource
method.
Syntax:
object.
toSource
()
toString method
This method converts a
Boolean
object to a string representing its value: i.e. either "true" or "false", and is called by JavaScript automatically whenever a
Boolean
object is used in a situation requiring a string. This method overrides the
Object.toString
method.
Syntax:
object.
toString
()
valueOf method
This method, which is usually called internally by JavaScript, returns a primitive value (either "true" or "false") for the
Boolean
object. It overrides the
Object.valueOf
method.
Syntax:
object.
valueOf
()
NOTE:
The
Boolean
object also inherits the
watch
and
unwatch
methods from the
Object
object.
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information