HuntExams Academy logo
JavaScriptBeginner#numbers

What is NaN and how do you check for it?

Answer

NaN is the numeric result of an invalid computation and is the only value not equal to itself. Use Number.isNaN, which does not coerce, rather than the legacy global isNaN.

Example

0/0;               // NaN
NaN === NaN;       // false
Number.isNaN('a'); // false
isNaN('a');        // true (coerces)

Related Interview Questions

1
JavaScriptIntermediate#numbers

Why is 0.1 + 0.2 !== 0.3?

Open
2
JavaScriptIntermediate#dom#events

What is event delegation useful for in dynamic lists?

Open
3
JavaScriptIntermediate#browser#performance

What is the difference between defer and async on a script tag?

Open