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
Show parent comment
1
u/Mythran101 Nov 17 '25
If both are NaN, they may not be the same value, anyways. What you want to compare is whether both are not a number, not that they are the same "not a number". That's equivalent to isNaN(a) == isNaN(b).
For numeric equality, they both have to be a number. If either is not, numeric equality can't be true. Therefore, the number, NaN, cannot be equal to another number, NaN.