alert(1/0)
alerts Infinity
and alert(1/-0)
alerts -Infinity
. alert(-1/-0)
alerts Infinity
, as I could expect when doing some operations with real numbers. I can't say that infinity is a measurable value. Does javascript think it is some number?
Infinity is a property of the global object. In other words, it is a variable in global scope. The initial value of Infinity is Number.
isFinite is a function property of the global object. You can use this function to determine whether a number is a finite number. The isFinite function examines the number in its argument. If the argument is NaN , positive infinity, or negative infinity, this method returns false ; otherwise, it returns true .
Any finite number is smaller than Infinity , and any finite number is bigger -Infinity . Comparing infinite values in JavaScript is easy: Infinity === Infinity is true .
Yes, Infinity
and -Infinity
are special values of the Number type. From the ES5 spec:
There are two other special values, called positive Infinity and negative Infinity. For brevity, these values are also referred to for expository purposes by the symbols +∞ and −∞, respectively. (Note that these two infinite Number values are produced by the program expressions
+Infinity
(or simplyInfinity
) and-Infinity
.)
Also note that NaN
is a value of the Number type too, despite it being an acronym for "not a number".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With