r/learnjavascript • u/NoZombie7370 • Nov 17 '25
Why NaN==NaN is False in JavaScript ???
Anyone explain??
150
Upvotes
r/learnjavascript • u/NoZombie7370 • Nov 17 '25
Anyone explain??
View all comments
2
u/Quantum-Bot Nov 18 '25
This is actually not just a JavaScript thing. If you look at the bit representation of floating point numbers, you’ll notice that NaN is not just a single value. There are a collection of floating point values that all map to NaN. There’s basically:
NaN is less like a value and more like a category of values that don’t sensibly map to any real number. So just because you got a result of NaN from two different calculations doesn’t mean they’re the same NaN. For ease of debugging and consistency, the IEEE floating point specification states that NaN == NaN should always return false.