whatstheoutput_

#32: Number.isNaN('abc') and Number.isNaN(NaN)

Topic: numbers · Difficulty: ★★

console.log(Number.isNaN('abc'));
console.log(Number.isNaN(NaN));

Output

false
true

Why

Number.isNaN performs NO type coercion at all: it first checks whether the argument's type is already 'number', and only then checks if it's the NaN value. 'abc' is a string, not a number, so it fails the type check immediately and returns false, regardless of what it would parse to. NaN is already a number and IS the NaN value, so it correctly returns true. This strictness makes Number.isNaN the safer choice over the global isNaN when you want to catch only genuine NaN values, not any non-numeric input.

More numbers puzzles

Play today's puzzle →