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.