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

In javascript, what type is NaN?

王林
王林 forward
2020-07-14 17:17:58 5494browse

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"

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

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

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete