Open In App

Integer Range in JavaScript

Last Updated : 24 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will know the different ranges of an integer variable in JavaScript. To get the ranges, we will use the MAX_VALUE and MIN_VALUE properties of ES5 JavaScript and the MAX_SAFE_INTEGER and MIN_SAFE_INTEGER properties of ES6 JavaScript.

The MAX_VALUE represents the biggest possible numeric value of a positive number that can be represented in JavaScript with the value 1.79E+308. The MIN_VALUE represents the smallest possible positive number representable in JavaScript within float precision with the value 5E-324(>0). The MAX_SAFE_INTEGER is a constant number that represents the minimum safe integer with the value  (253 – 1). The MIN_SAFE_INTEGER is a constant number that represents the negative value of the MAX_SAFE_INTEGER with the value (-1)x(253-1).

We will understand the above concept through examples.

Example 1: To show the range of the integer using MAX_VALUE and MIN_VALUE of ES5 JavaScript.

Javascript




<script>
    function Range() {
        document.write("The minimum value of integer is: "
            + Number.MIN_VALUE + "<br>");
    document.write("The maximum value of integer is: "
    +Number.MAX_VALUE+"<br>");
}
        Range();
</script>


Output:

The minimum value of integer is: 5e-324
The maximum value of integer is: 1.7976931348623157e+308

Example 2: To show the range of the integer using MAX_SAFE_INTEGER and MIN_SAFE_INTEGER of ES6 JavaScript.

Javascript




<script>
    function Range() {
        document.write("The minimum value of integer is: "
            + Number.MIN_SAFE_INTEGER + "<br>");
    document.write("The maximum value of integer is: "
    +Number.MAX_SAFE_INTEGER+"<br>");
}
        Range();
</script>


Output: 

The minimum value of integer is: -9007199254740991
The maximum value of integer is: 9007199254740991


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads