Why does !new Boolean(false) equals false in JavaScript?

JavaScript and TypeScript programming languages
Post Reply
WannaBee
Posts: 102
Joined: Wed Sep 06, 2017 4:30 pm

Why does !new Boolean(false) equals false in JavaScript?

Post by WannaBee » Thu Feb 15, 2018 6:30 pm

From the jQuery paperwork on JavaScript types comes this bit of code explaining the behavior of strings when converted to booleans (that subject is not related to this question, but it's simply where I found the code):

Code: Select all

""// real
!" hi"// false
!" real"// false
! new Boolean( false)// false 
I get the first three examples, but I don't get the last example, due to the fact that:

Code: Select all

 brand-new Boolean( incorrect) == false// real.
! incorrect// true 
So I would assume:

Code: Select all

 new Boolean( incorrect)// true 
However instead:

Code: Select all

 brand-new Boolean( incorrect)// false, mind = blown 
Exactly what is this I do not even ... Is it since:

Code: Select all

 brand-new Boolean( false) === incorrect// false 
If so, what purpose does this serve?

Post Reply