Number.MAX_VALUE
Holds the largest finite number JavaScript can represent, about 1.7976931348623157e+308.
Number.MAX_VALUE- Added in JavaScript ES1
Return value
numberThe largest representable positive finite number, 2^1024 - 2^971, approximately 1.7976931348623157e+308. The property is non-writable, non-enumerable and non-configurable.
Errors
Nothing on read; assigning to it throws a TypeError in strict mode, because the property is non-writable.
This is the ceiling of the double-precision format: the largest finite value a JavaScript number can hold. Anything that would land above it becomes Infinity, and the original magnitude is lost for good — there is no way to recover it from the result.
When to reach for it
Mostly as documentation of where overflow happens, and occasionally as an initial value when you are searching for a minimum over unbounded positive quantities. For that job Number.POSITIVE_INFINITY is the better seed, since it also beats any value that has itself already overflowed.
What trips people up
Two things. First, the check if (a * b > Number.MAX_VALUE) looks sensible but is dead code: by the time the multiplication has been evaluated the result is already Infinity, which is not greater than MAX_VALUE in any useful sense — it simply is the overflow. Test the result with Number.isFinite() instead.
Second, precision up here is dreadful. The gap between adjacent doubles near MAX_VALUE is about 2e292, so adding 1e291 changes nothing at all while adding 1e292 tips the value straight to Infinity. Exactness for integers ends far earlier, at Number.MAX_SAFE_INTEGER.
Example
When to use it
- Detecting overflow after a chain of multiplications or an exponential growth loop.
- Documenting the finite ceiling when writing a numeric range validator.
- Seeding a search for the minimum of a set of positive values.
Frequently asked questions
What is the largest number in JavaScript?
Number.MAX_VALUE, approximately 1.7976931348623157e+308, is the largest finite number. Above it every value is Infinity. If you need large whole numbers rather than large magnitudes, the relevant limit is Number.MAX_SAFE_INTEGER.
What is the difference between MAX_VALUE and MAX_SAFE_INTEGER?
MAX_VALUE (about 1.8e308) is the largest value that exists at all; MAX_SAFE_INTEGER (about 9e15) is the largest integer that is still exact. Between the two, numbers are representable but neighbouring integers get rounded together.
How do I check for numeric overflow in JavaScript?
Call Number.isFinite() on the result: overflow turns it into Infinity or -Infinity. Comparing against Number.MAX_VALUE before the operation does not help, because the overflow happens inside the arithmetic itself.
More examples
Watching a growth loop hit the ceiling
Each pass multiplies by 1e100, so the value walks 1e100, 1e200, 1e300 and then falls off the edge. The fourth line prints Infinity with isFinite false — the magnitude 1e400 has no representation, and nothing about the result records how far past the limit it went.
let v = 1;
for (let i = 1; i <= 4; i++) {
v = v * 1e100;
console.log(i, v, Number.isFinite(v));
}Guard the result, not the operands
safeProduct works because it inspects what the multiplication actually produced. The last line shows why the naive guard is useless: the comparison is true, but it is comparing Infinity, and the real product is unrecoverable by then.
function safeProduct(a, b) {
const p = a * b;
return Number.isFinite(p) ? p : "overflow";
}
console.log(safeProduct(1e200, 1e100)); // 1e+300
console.log(safeProduct(1e200, 1e200)); // overflow
// The naive test never fires, because Infinity > MAX_VALUE
// is the only thing it can ever see
console.log(1e200 * 1e200 > Number.MAX_VALUE); // true, but the value is gone
Discussion