# double negation !!
Double negation in JavaScript what is the purpose : stackoverflow.com
It casts to boolean. The first !
negates it once, converting values like so:
undefined
totrue
null
totrue
+0
totrue
-0
totrue
''
totrue
NaN
totrue
false
totrue
- All other expressions to
false
Then the other !
negates it again. A concise cast to boolean, exactly equivalent to ToBoolean simply because !
is defined as its negation. It’s unnecessary here, though, because it’s only used as the condition of the conditional operator, which will determine truthiness in the same way.