JavaScript Infinity Property

Below is the example of the Infinity Property.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script>
        function test() {
            document.write(
            -3.645464512375121213E+1203466 +
            "<br>"
            + 3.4548643575312453512345E+1203466);
        }
        test();
    </script>

    chevron_right

    
    

  • Output:
    -Infinity
    Infinity

The Infinity Property used to display Infinity when the floating point number’s upper limit is exceeded and -Infinity when the floating point number’s lower limit is exceeded. Here, Infinity denotes Positive Infinity and -Infinity represents Negative Infinity.

Syntax:

floating point no.

Return Value: It returns Infinity to represent Positive Infinity and -Infinity to represent Negative Infinity.

More example code for the above property are as follows:
Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>
          Geeks
      </h1>
        <button onclick="test()">
          Press
      </button>
        <p>
          3.4576917263943217389012348562315E+1203466 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>
  
        <script>
            function test() {
                document.getElementById(
                  "gfg").innerHTML =
                  -3.4576917263943217389012348562315E+1203466 +
                  "<br>"
                  + 3.4576917263943217389012348562315E+1203466;
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

Supported Browsers:

  • Google Chrome
  • Firefox
  • Internet Explorer
  • Safari
  • Opera
  • full-stack-img




    My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.