JavaScript Number NaN Property

Definition and usage

In JavaScript,NaN is the abbreviation for "Not-a-Number".

In JavaScript,NaN is an invalid number.

global NaN property and Number.Nan properties are the same.

The NaN property is a special value representing non-numeric values. This property is used to indicate that a value is not a number. The Number object can be set to this value to indicate that it is not a numeric value.

Tip:Please use isNaN() Global function to determine whether a value is a NaN value.

See also:

Global isNaN() method

Number.isNaN() method

Example

let x = Number.NaN;

Try it yourself

let x = NaN;

Try it yourself

syntax

Number.NaN

explains

Number.NaN is a special value that indicates that the result of some arithmetic operations (such as the square root of a negative number) is not a number. The method parseInt() and parseFloat() This value is returned when the specified string cannot be parsed. For some functions that return valid numbers in common cases, this method can also be used, using Number.NaN to indicate its error conditions.

JavaScript uses NaN The form of output Number.NaN. Note thatNaN The result of comparison with other numeric values is always unequal, including itself. Therefore, it cannot be compared with Number.NaN Comparison to detect whether a value is a number, and can only be called isNaN() for comparison.

In ECMAScript v1 and subsequent versions, the predefined global properties can also be used NaN Instead of Number.NaN.

Browser support

Number.NaN It is an ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη