The positive infinity in Javascript is a number that is constant and represents a value that is the 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: It is different from mathematical infinity in the following ways.
- If we divide any positive number by positive infinity, we will get a 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:
html
< body > < h1 style = "color: green;" > neveropen </ h1 > < h3 > What is positive infinity in JavaScript? </ h3 > < button onclick = "geekPositiveInfinity()" > Generate positive infinite </ button > < p id = "geek" ></ p > < script >; function geekPositiveInfinity() { var n=(Number.MAX_VALUE)*2; document.getElementById("geek").innerHTML= "Here the number generated is twice of Number.MAX_VALUE"+"< br >"+ " which is greater than upper limit"+"< br >< br >"+n; } </ script > </ body > |
Output:
Example 2:
HTML
< body > < h1 style = "color: green;" > neveropen </ h1 > < h3 > Positive infinity in JavaScript </ h3 > < h4 >Operations with positive infinity</ h4 > < ol > < li id = "divide" > < b >Divide any number by Positive infinity</ b > < br > 561 / Number.POSITIVE_INFINITY = </ li > < br > < li id = "divideNeg" > < b >Divide negative number by infinity</ b > < br > -123 / Number.POSITIVE_INFINITY = </ li > < br > < li id = "mulzero" > < b >0 multiply by Positive infinity</ b > < br > 0 * Number.POSITIVE_INFINITY = </ li > < br > < li id = "nanmul" > < b >NAN multiply by Positive infinity</ b > < br > NAN * Number.POSITIVE_INFINITY = </ li > < br > < li id = "dividepos" > < b >Divide Positive infinity by Negative number(except Negative Infinity)</ b > < br > Number.POSITIVE_INFINITY / -123 = </ li > < br > < li id = "divideposinf" > < b >Divide Positive infinity by Positive number</ b > < br > 0 / Number.POSITIVE_INFINITY = </ li > < br > < li id = "divideself" > < b >Divide Positive infinity by Positive Infinity or Negative infinity</ b > < br > Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY = </ li > </ ol > < button onclick = "calc()" >Click Here to calculate</ button > < script > function calc() { document.getElementById("divide").innerHTML+=561/Number.POSITIVE_INFINITY; document.getElementById("divideNeg").innerHTML+=-123/Number.POSITIVE_INFINITY; document.getElementById("mulzero").innerHTML+=0*Number.POSITIVE_INFINITY; document.getElementById("nanmul").innerHTML+=NaN*Number.POSITIVE_INFINITY; document.getElementById("dividepos").innerHTML+=Number.POSITIVE_INFINITY/-123; document.getElementById("divideposinf").innerHTML+=0/Number.POSITIVE_INFINITY; document.getElementById("divideself").innerHTML+=Number.POSITIVE_INFINITY/Number.POSITIVE_INFINITY; } </ script > </ body > |
Output:
Recommended Article: JavaScript Infinity Property