Talk:Core JavaScript 1.5 Reference:Global Objects:Boolean
From MDC
The following code actually produces a "false" response:
function booleanObject(){ x = new Boolean(false); if (x) alert(x);
}
This seems to contradict the following text from the page at Mozilla.org on booleans. Can anyone clarify whether boolean objects actually equate as true when a conditional statement is used if the object is stated as false?
Description
Do not confuse the primitive Boolean values true and false with the true and false values of the Boolean object.
Any object whose value is not undefined or null, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement. For example, the condition in the following if statement evaluates to true:
x = new Boolean(false); if (x) //the condition is true
This behavior does not apply to Boolean primitives. For example, the condition in the following if statement evaluates to false:
x = false; if (x) //the condition is false
The point is:
function checkFalse(x) {
if(x)
alert("hey!");
}
checkFalse(new Boolean(false)); // this shows an alert
checkFalse(false); // this does not
--Nickolay 08:41, 19 November 2005 (PST)