What does javascript nan mean?

藏色散人
Release: 2023-01-07 11:46:19
Original
6102 people have browsed it

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
Copy after login

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>
Copy after login

Output:

Nan
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!