Skip to content

JavaScript NaN property | Not-A-Number

  • by

JavaScript NaN’s full form is “Not-a-Number”. The global NaN property is a value representing Not-A-Number.


NaN is a property of the global object. In other words, it is a variable in the global scope.

JavaScript NaN

Simple example code

<!DOCTYPE html>

    let x = Number.NaN;

    let z = NaN;




JavaScript NaN property

Standard built-in objects – NaN

function sanitise(x) {
  if (isNaN(x)) {
    return NaN;
  return x;

// Output: "1"

// Output: NaN

Testing against NaN

NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(Number.NaN);  // true
Number.isNaN(NaN);  // true

function valueIsNaN(v) { return v !== v; }
valueIsNaN(1);          // false
valueIsNaN(NaN);        // true
valueIsNaN(Number.NaN); // true

Do comment if you have any doubt or suggestions on this JS NaN topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

Your email address will not be published. Required fields are marked *