Why does a not-a-number value fail every equality comparison, even against itself?
The earlier questions in this topic covered the basic types that JavaScript has and how the typeof operator reports them. This answer looks at the one special number value that behaves differently from every other value, and understanding it will save you from a very confusing bug.
The reason is that this value is not a number in the arithmetic sense at all. It comes from the IEEE 754 floating point standard, which defines a special result for operations that produce a meaningless answer. Dividing zero by zero does it, taking the square root of a negative number does it, and parsing a text value that contains no digits at all does it. The standard requires that this result is never equal to any value, including another copy of itself.
The reason behind that rule is soundness. If a failed calculation compared equal to itself, then a piece of code like if (result === expected) would pass when both sides were the result of a broken calculation, and the failure would be invisible. Making the value unequal to everything forces you to deal with it.
That design has one visible consequence. The standard way to test for it is the Number.isNaN function, and not the equality operators. The older global isNaN function is different and more dangerous. It converts its argument into a number first, so isNaN('hello') is true even though the text itself is not the special value, and isNaN(undefined) is also true. The static method only returns true for the actual special value.
There is a third comparison to know about as well. Object.is uses the SameValue algorithm, and under that algorithm the special value is equal to itself. That is why Object.is(NaN, NaN) is true while NaN === NaN is false. The stricter algorithm also tells a positive zero apart from a negative zero, where the strict operator treats them as the same value.