Open In App

JavaScript Infinity Property

Last Updated : 09 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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;">
            GeeksforGeeks
        </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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads