What is positive infinity in JavaScript?
The positive infinity in Javascript is a number which is constant and represents a value which is highest available.It can be generated using a self made function or by an arithmetic operation.
Note: JavaScript shows the POSITIVE_INFINITY value as Infinity.
Positive Infinity is different from mathematical infinity in the following ways:
- The product of two positive infinity is positive infinity
- Product of positive and negative infinity is negative infinity
- If we divide any positive number by positive infinity, we will get positive 0
- If we divide any negative number by positive infinity, we will get negative 0
- 0 multiplied by positive infinity is NaN
- NaN multiplied by positive infinity is NaN
- We get negative infinity when we divide positive infinity by any negative number (except negative infinity)
- We get positive infinity when we divide positive infinity by any positive number (except positive infinity)
- Positive infinity divided by either positive or negative infinity is NaN
Syntax:
Number.POSITIVE_INFINITY
Example 1:
<!DOCTYPE html> < html > < body > < style > h1 { color: green; } </ style > < h1 >GeeksforGeeks</ h1 > < h1 >What is positive infinity in JavaScript?</ h1 > < button onclick = "geekPositiveInfinity()" > Generate positive infinite </ button > < p id = "geek" ></ p > < script > function geekPositiveInfinity() { //positive value greater than the largest // representable number in JavaScript var n = (Number.MAX_VALUE) * 2; document.getElementById("geek").innerHTML = n; } </ script > </ body > </ html > |
chevron_right
filter_none
Output:
Example 2:
<script> function checkPositiveInfinity(x) { if (x === Number.POSITIVE_INFINITY) { return 'Number is Positive Infinity' ; } return x; } console.log(checkPositiveInfinity(Number.MAX_VALUE * 2)); </script> |
chevron_right
filter_none
Output:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Apple Safari
- Opera
- Internet Explorer/Edge