Home  >  Article  >  Web Front-end  >  How to strictly judge NaN in JavaScript

How to strictly judge NaN in JavaScript

小云云
小云云Original
2018-02-22 09:19:161601browse

Delete all false values ​​in the array.

In JavaScript, false values ​​include false, null, 0, "", undefined and NaN.

For NaN judgment, JS provides the function isNaN(). However, using the isNaN() function can only determine whether the variable is non-numeric, but cannot determine whether the variable value is NaN.

So, applying the properties of NaN:


> NaN === NaN;
false //永远返回false

We can use === to determine whether the variable is NaN. You only need to determine whether the variable is equal to itself. If not, the value of the variable is NaN.

Related recommendations:

Detailed explanation of usage examples of undefined, null, NaN, etc. in javascript

Articles about is_nan Recommend 4 articles

Detailed explanation of the judgment of Inf and Nan in Python


The above is the detailed content of How to strictly judge NaN in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

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