NaN === false
=> false, isn\'t NaN falsy?NaN === NaN
=> false, but !!NaN === !!NaN
=> trueI\'v
- Why NaN === false => false, isn't NaN falsy?
NaN
as you are using, is a global property initialized with value of Not-A-Number. It's not boolean. It's NaN data type as defined by IEEE 754.
It's the "same thing" you compare null === false
(or even null == false
).
In this case, there is no difference using sctric equal or not: NaN == false
, also will return false!
- Why NaN === NaN => false, but !!NaN === !!NaN => true
2.1. NaN ==== NaN
, is false by definition.
2.2. But in !!NaN === !!NaN
, you aren't comparing NaNs anymore, when you do ![value], you "evaluate" it (or cast to a boolean).
I'm gonna now explain with null
, because it's more used, so you can apply it to NaN
:
Casting NaN, it's the same thing that casting null
.
null == false? true : false // false! because it's not a bool false.
!null? true: false // true! because !null -> true -> if(true)...
More Refs:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.1.1
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN