Skip to content
Related Articles

Related Articles

Improve Article
JavaScript Number.MAX_SAFE_INTEGER Constant
  • Last Updated : 08 Sep, 2020

Below is the example of the Number.MIN_SAFE_INTEGER Constant.

  • Example:




    <script type="text/javascript">
        document.write(Number.MIN_SAFE_INTEGER); 
    </script
  • Output:

    9007199254740991

The JavaScript Number.MAX_SAFE_INTEGER is a constant number that represents the minimum safe integer. This constant has a value of (253 – 1). Here safe refers to the ability to represent integers and to compare them.

Example:

Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2

The above expression will evaluate to true which is actually mathematically NOT correct.



Syntax:

Number.MAX_SAFE_INTEGER

Return Value: A constant number.

Example 1: Below example illustrates the usage of Number.MAX_SAFE_INTEGER




<!DOCTYPE html>
<html lang="en">
  
<body>
    <h1 style="color: green;">GeeksforGeeks</h1>
    <script type="text/javascript">
        const a = Number.MAX_SAFE_INTEGER + 1;
        const b = Number.MAX_SAFE_INTEGER + 2;
  
        console.log(Number.MAX_SAFE_INTEGER);
        console.log(a);
        console.log(a === b);
    </script>
</body>
  
</html>

Output:

Example 2: Below example illustrates the usage of the constant Number.MAX_SAFE_INTEGER using Math.pow() function.




<!DOCTYPE html>
<html lang="en">
  
<body>
    <h1 style="color: green;">GeeksforGeeks</h1>
    <script type="text/javascript">
        const a = Number.MAX_SAFE_INTEGER;
        const b = -(Math.pow(2, 53) - 1);
  
        console.log(a);
        console.log(b);
        console.log(a === b);
    </script>
</body>
  
</html>

Output:

Supported Browsers:

  • Chrome
  • Internet Explorer (Not Supported)
  • Firefox
  • Edge
  • Safari
  • Opera



My Personal Notes arrow_drop_up
Recommended Articles
Page :