JavaScript: 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 JavaScript: Number Constructor

Type of NaN is "number".

〔►see JavaScript: 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 JavaScript: Number.isNaN

〔►see JavaScript: isNaN


Number Topic

  1. JavaScript: Number Object
  2. JavaScript: Number Constructor
  3. JavaScript: Number.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.