NaN, null vs undefined, and Number Precision

The three small-but-everywhere quirks: NaN is not equal to itself, null vs undefined have different meanings, and 0.1 + 0.2 isn't 0.3.

Step 1 of 6

NaN: the value not equal to itself

NaN stands for Not-A-Number and is the result of meaningless math: 0/0, Math.sqrt(-1), Number("hello"). It exists because the IEEE 754 floating-point spec demands that broken math returns a defined value rather than crashing.

NaN has one famous property: it is NOT equal to itself. NaN === NaN is false. This is why JavaScript ships Number.isNaN(x) — the right way to check.

Tip

Always use Number.isNaN, not the global isNaN. The global one coerces its argument first — isNaN("hello") returns true because "hello" coerces to NaN, which is misleading. Number.isNaN("hello") correctly returns false because "hello" is not actually NaN.

Learn more on MDN