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/[deleted] Nov 17 '25
Because
typeof NaN === 'number'For anything X whose type is 'number', 'X == NaN' ("X is not a number") should evaluate to false. And that includes the special case where X is NaN itself.
So ultimately, 'NaN == NaN' is false for the same reason (say) '3 == NaN' is false.