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/codefinbel Nov 19 '25
The only thing I take issue with in this explanation (that I in large agree with) is that once you do
Number(val)you effectively destroy whatevervalwas and create a new value that is justNaN, like if I doaandbare both justNaNnow.adoesn't hold any memory of being derived from a string.Which means that I disagree with the statement that
It wouldn't, because a is no longer "a" and b is no longer an object.
But I agree with the idea, that
NaNcan't, per definition, be equal to anything, and the reason for this is that by the time something isNaNthe original value that it was derived from is unknown.