3

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?

Finit
  • 43
  • 6

1 Answers1

4

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.

CertainPerformance
  • 260,466
  • 31
  • 181
  • 209
  • Another, why is the output of 'console.log((new Boolean( new Boolean(false))))' nothing? I think it will output "{}" in the console. – Finit Apr 22 '18 at 17:58
  • For me, it outputs `Boolean {true}`; `__proto__:Boolean[[PrimitiveValue]]: true` https://jsfiddle.net/r3qared0/ – CertainPerformance Apr 22 '18 at 18:51
  • ok, thanks. My chrome did not work well. I can get same result as you in normal Chrome. – Finit Apr 23 '18 at 03:15