Skip to main content
0:04est. 3 min

Intro Notes

Notes

isNAN check - quick learning notes
Source: http://adripofjavascript.com/blog/drips/the-problem-with-testing-for-nan-in-javascript.html

What is NaN?
- NaN means "Not a Number".
- You commonly get it from failed math or failed parsing.
Example: 42 / "General Zod" -> NaN
Example: parseInt("Doomsday", 10) -> NaN

Common mistakes:
- value === NaN is always false.
Reason: NaN is the only JS value not equal to itself.
- Global isNaN(value) can be misleading.
It checks "cannot be coerced to number", not strict NaN.
Example: isNaN("Jor El") -> true (false positive for many use cases)

Best checks to remember:
1) Modern preferred:
Number.isNaN(value)
2) Universal fallback trick:
value !== value // true only for NaN

Quick interview-friendly utility:
function isActualNaN(value) {
return Number.isNaN ? Number.isNaN(value) : value !== value;
}

Mental model:
- If you need strict NaN detection, use Number.isNaN.
- If you need broad "is this numeric-like?" behavior, global isNaN may be intentional.