JS: NaN

By Xah Lee. Date: .

NaN is a primitive value that means “Not a Number”.

NaN is typically returned when converting a value to number that doesn't make sense.

// convert string to number
// if arg does not make sense, result is NaN
console.log ( Number ("xyz")  ); // NaN

〔►see JS: Number Constructor

Type of NaN is "number".

〔►see JS: Data Types

console.log ( typeof NaN === "number" ); // true

NaN === NaN returns false.

console.log ( NaN === NaN ); // false

To test if a value is NaN, use Number.isNaN or the global function isNaN.

〔►see JS: Number.isNaN

〔►see JS: isNaN

Reference

Number Topic


  1. JS: Number Object
  2. JS: Number Constructor
  3. JS: Number.prototype
Like what you read? Buy JavaScript in Depth