NaN

A special value representing Not-A-Number. This value is represented as the unquoted literal NaN. NaN is a read-only property.

Property of

Number

Description

JavaScript prints the value Number.NaN as NaN.

NaN is always unequal to any other number, including NaN itself; you cannot check for the not-a-number value by comparing to Number.NaN. Use the isNaN function instead.

You might use the NaN property to indicate an error condition for a function that should return a valid number.

Example

In the following example, if month has a value greater than 12, it is assigned NaN, and a message is displayed indicating valid values.

var month = 13
if (month < 1 || month > 12) {
      month = Number.NaN
      alert("Month must be between 1 and 12.")
}