JavaScript .MAX_SAFE_INTEGER

jjw's avatar
Published Aug 1, 2025
Contribute to Docs

The .MAX_SAFE_INTEGER static data property represents the maximum safe integer in JavaScript, which is:

$$ 2^{53} - 1 = 9007199254740991 $$

It’s the largest integer that can be safely represented using the Number type without losing precision. This property is part of the Number class. To check if a value is a safe integer, use the .isSafeInteger() method. For integers larger than this limit, consider using the BigInt type instead.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

Number.MAX_SAFE_INTEGER;

Parameters:

None as it’s a static data property, not a function.

Return value:

Returns the largest safe integer representable by JavaScript’s Number type.

Example

This example demonstrates how .MAX_SAFE_INTEGER defines the upper limit for safe integers in JavaScript:

console.log(Number.MAX_SAFE_INTEGER);
console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER));
console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1));

The output produced by this code is:

9007199254740991
true
false

Codebyte Example

A codebyte example showing why it’s best to avoid numbers larger than .MAX_SAFE_INTEGER:

Code
Output
Loading...

Both a and b evaluate to the same value because they exceed the maximum safe integer JavaScript can represent accurately. When numbers go beyond this limit, JavaScript starts to lose precision, which can lead to incorrect comparisons and unexpected results.

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours