Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinity is some number in javascript?

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?

like image 581
nicael Avatar asked Jun 11 '14 15:06

nicael


People also ask

Is infinity a number in JavaScript?

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.

How do you handle infinity in JavaScript?

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 .

Is infinity true in JavaScript?

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 .


1 Answers

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".

like image 70
James Allardice Avatar answered Sep 30 '22 01:09

James Allardice