#31: isNaN('abc')
Topic: numbers · Difficulty: ★
console.log(isNaN('abc'));Output
true
Why
The global isNaN() function does NOT check whether its argument literally IS the value NaN. Instead, it first coerces its argument to a number with ToNumber, and THEN checks whether the result is NaN. Number('abc') fails to parse and produces NaN, so isNaN('abc') reports true — even though the string 'abc' obviously isn't the numeric value NaN. This implicit coercion is exactly why Number.isNaN was added later as a strict, no-coercion alternative.