Difference: Number.isNaN does not have type conversion behavior, and isNaN will try to convert the parameter into Number type. isNaN only determines whether the incoming parameter can be converted into a number, and does not strictly determine whether it is equal to NaN; while Number.isNaN determines whether the incoming parameter is strictly equal to NaN.
Recommended tutorial: "JavaScript Video Tutorial"
## isNaN
When we pass a parameter to isNaN, its original intention is to try to convert the parameter into Number type through the Number() method. If it succeeds, it returns false. If it fails, it returns true.
So isNaN only determines whether the incoming parameter can be converted into a number, and does not strictly determine whether it is equal to NaN.
Example:Number('测试')
console.log(isNaN('测试')) //true
Number. isNaN
# Determines whether the incoming parameter is strictly equal to NaN (that is, ===).
So under what circumstances is Number.isNaN generally used? When two variables are operated on, we can use Number.isNaN to determine whether its value is NaNconsole.log(Number.isNaN(1/'测试')); //输出true
The difference between the two
The biggest difference between Number.isNaN and isNaN is that Number.isNaN does not have type conversion behavior.
console.log(isNaN('测试')) //true console.log(Number.isNaN('测试')) //false
Programming Teaching! !
The above is the detailed content of What is the difference between isNaN and Number.isNaN in js. For more information, please follow other related articles on the PHP Chinese website!