JavaScript Infinity Property

The Infinity Property is used to display Infinity when the floating point number’s upper limit is exceeded and -Infinity is displayed when the floating point number’s lower limit is exceeded. Here, Infinity denotes Positive Infinity, and -Infinity represents Negative Infinity. Also, the upper limit of the floating point number is 1.7976931348623157e+308 and the lower limit is -1.797693134862316E+308
Syntax:
Infinity
Return:
Infinity // For positive infinity -Infinity // For negative infinity
Example 1:
JavaScript
<script> function test() { console.log( -3.645464512375121213E+1203466 + "<br>" +3.4548643575312453512345E+1203466); } test(); </script> |
Output:
-Infinity Infinity
Example 2:
html
<body> <center> <h1 style="color: green;"> zambiatek </h1> <h3> Js Infinity property </h3> <button onclick="test()"> Press </button> <p> 1.797693134862315E+308 is the limit of a Floating Point Number. </p> <h4> Clicking the Press button will showcase the Javascript Infinity Property. </h4> <p id="gfg"></p> </center> <script> function test() { document.getElementById("gfg") .innerHTML="-1.797693134862315E+309 will be replaced by: "+ -1.797693134862315E+309+ "<br>"+ "1.797693134862315E+309 will be replaced by: " + 1.797693134862315E+309; } </script> </body> |
Output:
To know more about the +ve infinity and -ve infinity please go through the attached links.
Supported Browsers: Since infinity is an ES1 feature it is supported by all browsers.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



