NaN is a global property representing a Not-a-Number value. It is a special value that indicates that the value is not a number.
NaN is usually the result of an operation that doesn't make sense or is arithmetically undefined, such as the the square root of a negative number:
Math.sqrt(-4); // NaN
NaN if the value specified in the parameter cannot be converted to or parsed as a number. The following examples all return
Number("foo"); parseInt("bar"); parseFloat("baz");
NaN is not equal to any other value, including itself. Consequently, you cannot determine whether a given value is not a number by comparing it to
NaN. Instead, the
isNaN() function can be used to check if the value is not a number:
var test_val = NaN; test_val == NaN; // false isNaN(test_val); // true
NaN should not be confused with
NaN indicates that the value of an expression is undefined, or is out of its domain of definition.