JavaScript .MAX_SAFE_INTEGER
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.
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:
9007199254740991truefalse
Codebyte Example
A codebyte example showing why it’s best to avoid numbers larger than .MAX_SAFE_INTEGER:
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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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