Home > Web Front-end > JS Tutorial > In javascript, what type is NaN?

In javascript, what type is NaN?

王林
Release: 2020-07-14 17:17:58
forward
5683 people have browsed it

In javascript, what type is NaN?

The NaN attribute represents a value that is "not a number". This special value occurs because the operation cannot be performed, either because one of its operands is not a number (for example, "abc" / 4), or because the result of the operation is not a number (for example, the divisor is zero).

(Recommended tutorial: js tutorial)

First of all, although NaN means "not a number", its type is Number.

console.log(typeof NaN === "number");  // logs "true"
Copy after login

Additionally, NaN is false when compared to anything - even itself:

console.log(NaN === NaN);  // logs "false"
Copy after login

If you want to test whether a number is equal to NaN, you can use value !== value. Will only produce true if the value is equal to NaN. In addition, ES6 provides a new Number.isNaN() function, which is a different function and more reliable than the old global isNaN() function.

The above is the detailed content of In javascript, what type is NaN?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template