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 return 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: Format Number
  2. JS: String to Number
  3. JS: Number Object
  4. JS: Number Constructor
  5. JS: Number.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon