Why JavaScript says that a number is not a number?
This question already has an answer here:
As I understand it, NaN
is a sentinel instance of the Number
class that represents, well, exactly what it stands for - numeric results that cannot be adequately represented. So 0/0
is not a number, in the sense that it's NaN
, but it is a Number
in terms of its type.
Perhaps it should have been called NaRN (Not a Representable Number).
If you have a variable and assign it the result of 0/0, the variable is still of numeric type, but the value is undefined (not a number). There are other conditions under which this can occur, but this illustrates what you are seeing.
You are confusing the type of your object with the value. NaN
is a specific value that a an object of type number
can be assigned with, for instance in the case of division of zero by zero or when trying to convert a number from a string that does not represent a number.
上一篇: 为什么静态方法被认为是一种方法?