isNaN function
Returns a Boolean value indicating whether the provided value is a reserved value NaN (not a number).
NaN means Not a Number
isNaN(numValue)
The required numvalue parameter is the value to check whether it is NAN.
illustrate
If the value is NaN, then the isNaN function returns true, otherwise it returns false. A typical case of using this function is to check the input values of the parseInt and parseFloat methods.
There is another way, the variable can be compared with itself. If the results of comparison are not equal, then it is NaN. This is because NaN is the only value that is not equal to itself.
Example of usage of isNaN function: For example, I have a textbox for entering numeric data. When submitting the form, I want to verify whether the value in the textbox is data, so we can use the isNaN function.
function checkValue()
{
if(isNaN())
{
alert("Please enter with numbers!");
return false;
}
}
A typical use of isNaN is to perform an advanced test for the input values of parseInt and parseFloat methods, but this simple result is not good. Although some textbooks may say the same, and even mistakenly think that it is a check for the return values of parseInt and parseFloat, it is both wrong.
parseInt and parseFloat are to convert a character type into a number. But there are error handling itself. If your input value is not a number, parseInt and parseFloat return a message: "is not number", but in general, we convert a string of numeric styles. Who would be bored to convert non-numeric types? Therefore, whether the parameters you enter are qualified can be checked first.
However, if we are conscious of the following behavior, we cannot use isNaN to check in advance. If the number starts with letters, it will not be possible to check in if isNaN.
If it is an empty string or a space, and isNaN is processed as the number 0, and parseInt and parseFloat return an error message, this isNaN check is not strict.
The two functions are independent and will not survive for whom. isNaN has nothing to do with parseInt/parseFloat.
Returns a Boolean value indicating whether the provided value is a reserved value NaN (not a number).
NaN means Not a Number
isNaN(numValue)
The required numvalue parameter is the value to check whether it is NAN.
illustrate
If the value is NaN, then the isNaN function returns true, otherwise it returns false. A typical case of using this function is to check the input values of the parseInt and parseFloat methods.
There is another way, the variable can be compared with itself. If the results of comparison are not equal, then it is NaN. This is because NaN is the only value that is not equal to itself.
Example of usage of isNaN function: For example, I have a textbox for entering numeric data. When submitting the form, I want to verify whether the value in the textbox is data, so we can use the isNaN function.
Copy the codeThe code is as follows:
function checkValue()
{
if(isNaN())
{
alert("Please enter with numbers!");
return false;
}
}
A typical use of isNaN is to perform an advanced test for the input values of parseInt and parseFloat methods, but this simple result is not good. Although some textbooks may say the same, and even mistakenly think that it is a check for the return values of parseInt and parseFloat, it is both wrong.
parseInt and parseFloat are to convert a character type into a number. But there are error handling itself. If your input value is not a number, parseInt and parseFloat return a message: "is not number", but in general, we convert a string of numeric styles. Who would be bored to convert non-numeric types? Therefore, whether the parameters you enter are qualified can be checked first.
However, if we are conscious of the following behavior, we cannot use isNaN to check in advance. If the number starts with letters, it will not be possible to check in if isNaN.
If it is an empty string or a space, and isNaN is processed as the number 0, and parseInt and parseFloat return an error message, this isNaN check is not strict.
The two functions are independent and will not survive for whom. isNaN has nothing to do with parseInt/parseFloat.