How to useNumber.MAX_SAFE_INTEGER Constant in Javascript

The MAX_SAFE_INTEGER constant in JavaScript is the property of the Number object. This constant holds the maximum safe integer. The safe integer is nothing but that any integer greater than this value may lose precision when represented as a number type in JavaScript.

Syntax:

Number.MAX_SAFE_INTEGER

Example: This example implements the above-mentioned approach

Javascript




const maxInteger = () => {
    return Number.MAX_SAFE_INTEGER;
};
console.log(
    `Max Safe Integer is: ${maxInteger()}`
);


Output

Max Safe Integer is: 9007199254740991





What is JavaScript’s highest integer value that a Number can go to without losing precision?

In this article, we are going to implement a JavaScript program that will return the highest integer value that the number can go to without losing precision.

Below are the three approaches using which we will get the highest integer value without losing precision

Table of Content

  • Using Number.MAX_SAFE_INTEGER Constant
  • Using Mathematical Operation
  • Using user-defined Function

Similar Reads

Approach 1: Using Number.MAX_SAFE_INTEGER Constant

...

Approach 2: Using Mathematical Operation

The MAX_SAFE_INTEGER constant in JavaScript is the property of the Number object. This constant holds the maximum safe integer. The safe integer is nothing but that any integer greater than this value may lose precision when represented as a number type in JavaScript....

Approach 3: Using User-Defined Function

...

Contact Us