"NaN Comparison Always Returns False" in JavaScript — What It Means and How to Fix It
What the JavaScript error "NaN Comparison Always Returns False" means and how to fix it.
Published October 30, 2026
NaN (Not a Number) is the only JavaScript value that is not equal to itself, so x === NaN is always false. Use Number.isNaN(x) instead.
What it means and why it happens
NaN appears from failed numeric conversions like Number('abc') or 0/0.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
NaN === NaN // false
Practical examples
Code that triggers it
if (value === NaN) { console.log('bad') } // never runsThe fix
if (Number.isNaN(value)) { console.log('bad') }Prefer Number.isNaN
isNaN('abc') // true (coerces)
Number.isNaN('abc') // false (no coercion)
Object.is(NaN, NaN) // trueCommon mistakes
- Comparing with === NaN.
- Using global isNaN on strings.
- Not validating parsed numbers.
Key takeaways
- NaN comparison always false: NaN (Not a Number) is the only JavaScript value that is not equal to itself, so x === NaN is always false.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Why is NaN !== NaN?
IEEE 754 defines NaN as unequal to everything, including itself.
How do I find which line caused NaN comparison always false?
The error message and stack trace show the file and line; start there and work backwards.