This is because, according to Section 4.3.23 of the ECMAScript Language Specification, NaN is defined as:
a numeric value that is an IEEE 754 "Not-a-Number" value
So this is a number, not something undefined or null. The meaning is further explained in Section 8.3.
...; to the ECMAScript code, all NaN values are indistinguishable from each other.
A comparison of equality with NaN is defined in Section 11.9.3 :
A comparison of x == y, where x and y are values, produces true or false. Such a comparison is performed as follows: If Type (x) is Number, then:
If x is NaN, return false.
If y is NaN, return false.
For comparison, you should use isNaN() instead:
isNaN(NaN)
Update
The value +undefined not a number, but it is nonetheless (albeit with a special value) and therefore not undefined. Just like casting undefined for a string gives a string value that is defined.
Ja͢ck source share