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.
x = new Boolean("false")
if(x)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 this code evaluates to true.
x = false
if(x)However, this does not apply to Boolean primitives, and the conditional statement in the following code evaluates to false.
x = Boolean(a+b)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. This example converts the expression 'a+b' to a Boolean value.
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("")All of these objects have an initial value of false.
myBool = new Boolean(false)
x = new Boolean(myBool)
x = new Boolean("false")In these examples the Boolean object 'x' has an initial value of true
Syntax: Object.constructor
This specifies a function to create an object's property and is inherited by all objects from their prototype.
Syntax: Object.prototype.name = value
This allows the addition of properties and methods to any object.
Syntax: Object.eval(string)
The eval method is deprecated as a method of Object, but is still used as a high level function. It evaluates a string of JavaScript in the context of an object.
Syntax: Object.toSource()
The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.
Syntax: Object.toString()
The toString method returns a string representing a specified object.
Syntax: Object.unwatch(property)
This method removes a watchpoint set for an object and property name with the watch method.
Syntax: Object.valueOf()
This method returns a primitive value for a specified object.
Syntax: Object.watch(property, handlerfunction)
This method adds a watchpoint to a property of the object.