Javascript Infinity

infinity, javascript

Solution

That's how ∞ works in mathematics. Infinity itself is not a number, it is a concept. The general idea is that `∞ + x = ∞ ∀ x`

∞ is, obviously, infinitely big. If you subtract an infinitely big thing from another infinitely big thing, you can't define what you have left. If the first infinity is bigger, you'll get a negative result, but if it's smaller then the result will be positive (basic rule of subtraction), but since both are infinitely big you have no way of knowing which is bigger (unless more information is given, such as the context leading to these infinities*). Therefore, as far as the computer is concerned, ∞ - ∞ is mathematically undefined, or Not a Number.

* Example: Let x = the sum of all positive integers, and y = the sum of each positive integer doubled. In this case, we can say that y > x, even though both are infinity.

Problem

Division by 0 gives this special value: ``` 3/0 output:Infinity ``` You can’t play positive and negative infinity against each other: ``` Infinity - Infinity output:NaN (Why?) ``` It also turns out that “beyond infinity” is still infinity: ``` Infinity + Infinity output:Infinity(this is accepted) 5 * Infinity Infinity(this is also accepted) ``` so why infinity-infinity evalutes to NaN?It should be infinity isn't it?Also i wanted to know why cant object be converted to primitive values?Sorry for posting two question at a time ,as this is the last question i can post.See here: ``` var obj = { valueOf: function () { console.log("valueOf"); return {}; // not a primitive }, toString: function () { console.log("toString"); return {}; // not a primitive } } Number(obj) //TypeError: Cannot convert object to primitive values ```

Original source