HTML and CSS Reference
In-Depth Information
“Not a number” is used in cases where an arithmetic operation produces a result that is not
a number. Confusingly, this type is still a number .
> a = 9/undefined
NaN
> typeof a
"number"
It would have potentially been more useful for JavaScript to generate an error in this scen-
ario.
Negative and positive infinity are also supported, and are most often generated when divid-
ing by 0:
> b = 6/0
Infinity
> b == Number.POSITIVE_INFINITY
true
> c = -6/0
-Infinity
> c == Number.NEGATIVE_INFINITY
true
Again, most programming languages would generate errors in these scenarios if confronted
with the integer value of 0, but since all numbers are floating point in JavaScript, it follows
the IEEE convention for floating point numbers and returns infinity.
Search WWH ::




Custom Search