Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Number.isNaN: an exact NaN test without coercion

Number.isNaN returns true only when its argument has Number type and is the special NaN value.

Version: ECMAScript 2015 onward; example target: Node.js 24.22.2

Syntax

Number.isNaN(number)

Number.isNaN(value) checks both Number type and the NaN value. It returns true for NaN produced by a failed numeric conversion or an undefined arithmetic operation, and false for every other Number, including Infinity and -0. A missing argument produces false because undefined is not a Number.

The method does not apply ToNumber: "NaN", "oops", undefined, objects, BigInt, and Symbol produce false without conversion or TypeError. The global isNaN differs because it converts first; therefore isNaN("oops") is true, but Number.isNaN("oops") is false, and some global-form conversions can throw. Number.isNaN is usually the safer test for a computation result.

The method has existed since ECMAScript 2015 and is not a constructor. The example explicitly converts readings with Number and then marks only a NaN result as invalid. Notice that Number("") is 0, so Number.isNaN does not replace checking whether empty text is permitted by the input format.

Examples

function parseReading(text) {
  const value = Number(text);
  return Number.isNaN(value) ? "invalid" : value.toFixed(1);
}

console.log(["18.5", "oops", ""].map(parseReading).join(" | "));
console.log(Number.isNaN(NaN), Number.isNaN("NaN"), Number.isNaN());
console.log(isNaN("oops"), Number.isNaN("oops"));
console.log(Number.isNaN(1n), Number.isNaN(Symbol("x")));

Result

18.5 | invalid | 0.0
true false false
true false
false false

Number.isNaN → validating the result of explicit reading conversion

Sources