Home  >  Article  >  Web Front-end  >  JavaScript uses the isNaN() function to determine whether a variable is a number_javascript tips

JavaScript uses the isNaN() function to determine whether a variable is a number_javascript tips

WBOY
WBOYOriginal
2016-05-16 17:22:141654browse

How to determine whether a variable is a number in javascript. Here we mainly introduce the isNaN() function in javascript.

Function:

isNaN() function is used to check whether its argument is a non-numeric value.

Syntax:

isNaN(x) x required. The value to detect.

Return value:

If x is the special non-numeric value NaN (or can be converted to such a value), the returned value is true. If x is any other value, returns false.

Explanation:

isNaN() function can be used to determine whether its parameter is NaN. This value represents an illegal number (such as the result obtained after dividing by 0) .
If NaN is compared with any value (including itself), the result is false, so to determine whether a value is NaN, you cannot use the == or === operators. Because of this, the isNaN() function is required.

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