Infinity is some number in javascript?

nicael picture nicael · Jun 11, 2014 · Viewed 15.6k times · Source

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?

Answer

James Allardice picture James Allardice · Jun 11, 2014

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 simply Infinity) and -Infinity.)

Also note that NaN is a value of the Number type too, despite it being an acronym for "not a number".