TIL: In JavaScript, isNaN("") returns false, but parseInt("") returns NaN. o_o

comments (single view)

isNaN returns true if the provided object is a Number, and equivalent to NaN.

No, that’s Number.isNaN. The global isNaN, which I used in the post, converts the supplied value to a number if it isn’t already, but it has such odd rules for doing so that the Mozilla web docs have an entire section talking about it.

(Also, “equivalent to NaN" is an odd phrase to use in this context; in JavaScript, NaN != NaN.)

View all comments