Why New Boolean(false) Is True?
Solution 1:
Says so in the docs:
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 = newBoolean(false);
if (x) {
// ...this code is executed
}
Directly from MDN.
Solution 2:
See MDN docs : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean .
It is stated :
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.
Solution 3:
It's as simple as this:
x
is a Boolean
object. (Logging it will show: Boolean {}
)
All objects evaluate to true
(See the first paragraph under "Description")
Solution 4:
var x = new Boolean();
when use the keyword new
,the variable created is an object type, object type value is always true
.
Solution 5:
Object is truthy. See http://james.padolsey.com/javascript/truthy-falsey/
so evaluating it without the implicit type conversion (when comparing to false
) is true.
Post a Comment for "Why New Boolean(false) Is True?"