That's an instance of the Boolean function, not a boolean primitive.
true
and false
in javascript are boolean primitives. When you use them with boolean operators, they behave as you would expect. For example true || false
is true
and true && false
is false
.
On the other hand, Boolean
is a special function which can convert other data types into boolean's (among other things). When you call new Boolean(false)
, you're creating a Boolean
object which contains the boolean primitive false
. That's the critical distinction in this case.
In short,
if(new Boolean())
uses javascript's truthy value rules. It is an object which is not null, so it's "true".
if(false)
is a boolean primitive and actually checks for true/false.