I do not understand what's going on
var x=new Boolean(false)
if(x){
console.log('plus')
}
console.log(x==false) //true
Why if(x) returns true ?
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 = new Boolean(false);
if (x) {
// ...this code is executed
}
Directly from MDN.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With