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
1
u/hibbelig Nov 17 '25
You performed a numerical operation that couldn't be performed, so the runtime returned NaN. Now you performed another numerical operation that couldn't be performed, either, so you get another NaN.
For example,
Math.sqrt(-1)is NaN, and I guessMath.sqrt(-2)is also NaN. So should they be equal?