Home >Web Front-end >Front-end Q&A >What does javascript nan mean?
javascript nan is a special value that represents a non-numeric value. This attribute is used to indicate that a value is not a number. You can set the Number object to this value to indicate that it is not a numeric value. The syntax is "Number. NaN".
The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
javascript nanWhat does it mean?
JavaScript NaN attribute
The NaN attribute is a special value that represents a non-numeric value. This attribute is used to indicate that a value is not a number. A Number object can be set to this value to indicate that it is not a numeric value.
Tip: Please use the isNaN() global function to determine whether a value is a NaN value.
Syntax
Number.NaN
Description
Number.NaN is a special value indicating that the result of certain arithmetic operations (such as finding the square root of a negative number) is not a number. The methods parseInt() and parseFloat() return this value when the specified string cannot be parsed. For some functions that normally return valid numbers, you can also use this method and use Number.NaN to indicate its error conditions.
JavaScript outputs Number.NaN as NaN. Note that NaN is always unequal when compared to other numbers, including itself. Therefore, you cannot compare with Number.NaN to test whether a value is a number, but can only call isNaN() for comparison.
In ECMAScript v1 and later versions, you can also use the predefined global property NaN instead of Number.NaN.
Tips and Notes
Tip: Please use isNaN() to determine whether a value is a number. The reason is that NaN is not equal to any value, including itself.
Example
Use NaN to indicate whether a value is a number:
<script type="text/javascript"> var Month=30; if (Month < 1 || Month > 12) { Month = Number.NaN; } document.write(Month); </script>
Output:
Nan
Recommended learning: "javascript Basic tutorial》
The above is the detailed content of What does javascript nan mean?. For more information, please follow other related articles on the PHP Chinese website!