Home  >  Article  >  Web Front-end  >  What does javascript nan mean?

What does javascript nan mean?

藏色散人
藏色散人Original
2021-09-01 11:56:086129browse

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".

What does javascript nan mean?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn