eg1:
var boo = new Boolean(false)
document.write(boo.valueOf())//false
eg2:
var boo1 = new Boolean(new Boolean(false))
document.write(boo1.valueOf())//true
Why two examples' output are different?
By the way:
console.log((new Boolean( new Boolean(false))))//nothing
document.write(new Boolean( new Boolean(false)))//true
Why is there nothing in the console?
Objects are truthy, and when you use new Boolean, you're calling the Boolean constructor, which returns an object. When new Boolean is called with a truthy value, it results in a object whose value is true. Thus, new Boolean(new Boolean(<anything>)) will result in a Boolean with a value of true.
But just don't do this - use literal booleans or Boolean(condition) instead.
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