Boolean
object is an object wrapper for a boolean value.Boolean
constructor:
new Boolean(value)
value |
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 |
Description
|
| |
---|
watch
and unwatch
methods from Object
.
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")
Object.constructor
.
Function.prototype
.toString()
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()
Object.toString
valueOf()
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.
x = new Boolean();
myVar=x.valueOf() //assigns false to myVar
Object.valueOf
Last Updated: 11/13/98 10:22:49
Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use