JavaScript has two number types: Number and BigInt.

The most frequently-used number type, Number, is a 64-bit floating point IEEE 754 number.

The largest exact integral value of this type is Number.MAX_SAFE_INTEGER, which is:

  • 253-1, or
  • +/- 9,007,199,254,740,991, or
  • nine quadrillion seven trillion one hundred ninety-nine billion two hundred fifty-four million seven hundred forty thousand nine hundred ninety-one

To put this in perspective: one quadrillion bytes is a petabyte (or one thousand terabytes).

"Safe" in this context refers to the ability to represent integers exactly and to correctly compare them.

From the spec:

Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number type (indeed, the integer 0 has two representations, +0 and -0).

To safely use integers larger than this, you need to use BigInt, which has no upper bound.

Note that the bitwise operators and shift operators operate on 32-bit integers, so in that case, the max safe integer is 231-1, or 2,147,483,647.

const log = console.log
var x = 9007199254740992
var y = -x
log(x == x + 1) // true !
log(y == y - 1) // also true !

// Arithmetic operators work, but bitwise/shifts only operate on int32:
log(x / 2)      // 4503599627370496
log(x >> 1)     // 0
log(x | 1)      // 1


Technical note on the subject of the number 9,007,199,254,740,992: There is an exact IEEE-754 representation of this value, and you can assign and read this value from a variable, so for very carefully chosen applications in the domain of integers less than or equal to this value, you could treat this as a maximum value.

In the general case, you must treat this IEEE-754 value as inexact, because it is ambiguous whether it is encoding the logical value 9,007,199,254,740,992 or 9,007,199,254,740,993.

Answer from Jimmy on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › MAX_SAFE_INTEGER
Number.MAX_SAFE_INTEGER - JavaScript | MDN
Number.MAX_SAFE_INTEGER represents ... The largest representable number in JavaScript is actually Number.MAX_VALUE, which is approximately 1.7976931348623157 × 10308....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › MAX_VALUE
Number.MAX_VALUE - JavaScript | MDN
October 22, 2025 - The Number.MAX_VALUE static data property represents the maximum numeric value representable in JavaScript.
Discussions

math - What is JavaScript's highest integer value that a number can go to without losing precision? - Stack Overflow
JavaScript has two number types: Number and BigInt. The most frequently-used number type, Number, is a 64-bit floating point IEEE 754 number. The largest exact integral value of this type is Number.MAX_SAFE_INTEGER, which is: More on stackoverflow.com
🌐 stackoverflow.com
Maximum Integer in Js
Fun question! So in JavaScript, every value with the "number" type is represented under the hood with a 64-bit (or "double-precision") floating point number. Floating point numbers represent a value with a combination of fractions and exponents, which allows them to represent a lot of numbers (with varying degrees of precision), but at the end of the day, the value still has to fit within 64-bits somehow. So there are limits. In this case, the highest number a 64-bit float can possibly represent happens to be 1.7976931348623157e+308 (this number is stored in the constant Number.MAX_VALUE should you ever need to reference it). Your value of 1e+309 is larger than that, so the best a 64-bit float can do is call it Infinity. Under the IEEE 754 floating-point standard (which JavaScript uses), there are some special values, like NaN and Infinity. You can basically think of NaN as "something went wrong with this number" and Infinity as "this number is bigger than I can do anything useful with". Both special values sort of infect anything they touch. The result of any math with NaN is NaN. The result of (almost) any math with Infinity is Infinity. console.log(NaN * 2); // NaN console.log(Infinity - 100); // Infinity console.log(Infinity * 0); // NaN Jumping back to those varying degrees of precision, the highest integer you can represent without losing any precision happens to be a good deal smaller than 1e+308. Since everything is actually a float under the hood, you can only get up to 253 - 1 (or 9,007,199,254,740,991) before you can't trust integer math to work right anymore (that number is stored in the constant Number.MAX_SAFE_INTEGER by the way). console.log(9007199254740991 + 10); // 9007199254741000 Now, the good news for anyone who loves big numbers, is that JavaScript recently added a new primitive type, "bigint". You can make a value a BigInt by adding an n to the end, or by calling BigInt on it. const num = 7; // <-- number const big = 7n; // <-- bigint const int = BigInt(7); // <-- bigint There are two big differences between BigInts and vanilla numbers. They are integers, not floating point. This means you can't represent fractions, but you also never lose precision. They are variable-bit. They start as 64-bit, but if the value gets to large, more bits are added. So with BigInt, we can represent big numbers. let x = 10n ** 309n; // e-notation not supported with BigInt console.log(x); // 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n And we can safely do big integer math. console.log(9007199254740991n + 10n); // 9007199254741001n But any decimal places just end up getting dropped. console.log(5n / 2n); // 2n More on reddit.com
🌐 r/learnjavascript
8
43
August 5, 2022
javascript - input type number - max value - Stack Overflow
I have an input However, if the user write manually for example 200, the input accept it. Is it something normal ? I can validate the entr... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Whats the difference between JS Number.MAX_SAFE_INTEGER and MAX_VALUE? - Stack Overflow
Number.MAX_SAFE_INTEGER 9007199254740991 Number.MAX_VALUE 1.7976931348623157e+308 I understand how MAX_SAFE_INTEGER is computed based on JavaScript's double precision floating point arithm... More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › jsref › jsref_max_value.asp
JavaScript MAX_VALUE Property
Number.MAX_VALUE returns the largest number possible in JavaScript.
Top answer
1 of 16
1011

JavaScript has two number types: Number and BigInt.

The most frequently-used number type, Number, is a 64-bit floating point IEEE 754 number.

The largest exact integral value of this type is Number.MAX_SAFE_INTEGER, which is:

  • 253-1, or
  • +/- 9,007,199,254,740,991, or
  • nine quadrillion seven trillion one hundred ninety-nine billion two hundred fifty-four million seven hundred forty thousand nine hundred ninety-one

To put this in perspective: one quadrillion bytes is a petabyte (or one thousand terabytes).

"Safe" in this context refers to the ability to represent integers exactly and to correctly compare them.

From the spec:

Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number type (indeed, the integer 0 has two representations, +0 and -0).

To safely use integers larger than this, you need to use BigInt, which has no upper bound.

Note that the bitwise operators and shift operators operate on 32-bit integers, so in that case, the max safe integer is 231-1, or 2,147,483,647.

const log = console.log
var x = 9007199254740992
var y = -x
log(x == x + 1) // true !
log(y == y - 1) // also true !

// Arithmetic operators work, but bitwise/shifts only operate on int32:
log(x / 2)      // 4503599627370496
log(x >> 1)     // 0
log(x | 1)      // 1


Technical note on the subject of the number 9,007,199,254,740,992: There is an exact IEEE-754 representation of this value, and you can assign and read this value from a variable, so for very carefully chosen applications in the domain of integers less than or equal to this value, you could treat this as a maximum value.

In the general case, you must treat this IEEE-754 value as inexact, because it is ambiguous whether it is encoding the logical value 9,007,199,254,740,992 or 9,007,199,254,740,993.

2 of 16
509

>= ES6:

Number.MIN_SAFE_INTEGER;
Number.MAX_SAFE_INTEGER;

<= ES5

From the reference:

Number.MAX_VALUE;
Number.MIN_VALUE;

console.log('MIN_VALUE', Number.MIN_VALUE);
console.log('MAX_VALUE', Number.MAX_VALUE);

console.log('MIN_SAFE_INTEGER', Number.MIN_SAFE_INTEGER); //ES6
console.log('MAX_SAFE_INTEGER', Number.MAX_SAFE_INTEGER); //ES6

Top answer
1 of 3
75
Fun question! So in JavaScript, every value with the "number" type is represented under the hood with a 64-bit (or "double-precision") floating point number. Floating point numbers represent a value with a combination of fractions and exponents, which allows them to represent a lot of numbers (with varying degrees of precision), but at the end of the day, the value still has to fit within 64-bits somehow. So there are limits. In this case, the highest number a 64-bit float can possibly represent happens to be 1.7976931348623157e+308 (this number is stored in the constant Number.MAX_VALUE should you ever need to reference it). Your value of 1e+309 is larger than that, so the best a 64-bit float can do is call it Infinity. Under the IEEE 754 floating-point standard (which JavaScript uses), there are some special values, like NaN and Infinity. You can basically think of NaN as "something went wrong with this number" and Infinity as "this number is bigger than I can do anything useful with". Both special values sort of infect anything they touch. The result of any math with NaN is NaN. The result of (almost) any math with Infinity is Infinity. console.log(NaN * 2); // NaN console.log(Infinity - 100); // Infinity console.log(Infinity * 0); // NaN Jumping back to those varying degrees of precision, the highest integer you can represent without losing any precision happens to be a good deal smaller than 1e+308. Since everything is actually a float under the hood, you can only get up to 253 - 1 (or 9,007,199,254,740,991) before you can't trust integer math to work right anymore (that number is stored in the constant Number.MAX_SAFE_INTEGER by the way). console.log(9007199254740991 + 10); // 9007199254741000 Now, the good news for anyone who loves big numbers, is that JavaScript recently added a new primitive type, "bigint". You can make a value a BigInt by adding an n to the end, or by calling BigInt on it. const num = 7; // <-- number const big = 7n; // <-- bigint const int = BigInt(7); // <-- bigint There are two big differences between BigInts and vanilla numbers. They are integers, not floating point. This means you can't represent fractions, but you also never lose precision. They are variable-bit. They start as 64-bit, but if the value gets to large, more bits are added. So with BigInt, we can represent big numbers. let x = 10n ** 309n; // e-notation not supported with BigInt console.log(x); // 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n And we can safely do big integer math. console.log(9007199254740991n + 10n); // 9007199254741001n But any decimal places just end up getting dropped. console.log(5n / 2n); // 2n
2 of 3
9
JavaScript uses double-precision floating point values to store numbers. The highest number you can store in this format is 1.7976931348623157e+308 or 2^1024. Anything higher than that is rounded to Infinity, as part of the floating point spec.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript | MDN
The Math.max() static method returns the largest of the numbers given as input parameters, or -Infinity if there are no parameters.
🌐
Medium
fullstackdojo.medium.com › number-max-value-vs-infinity-in-javascript-cbda41368717
Number.MAX_VALUE vs. Infinity in JavaScript | by DSL | Medium
June 15, 2024 - - Number.MAX_VALUE: This is the largest finite number representable in JavaScript. Its value is approximately 1.7976931348623157 * 10^{308}. It’s used when you need to initialize variables to a very high value within the range of finite numbers.
Find elsewhere
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Number › MAX_VALUE
JavaScript Number MAX_VALUE - Get Maximum Value | Vultr Docs
December 2, 2024 - The output will show the value of 1.7976931348623157e+308, which is close to the upper limit of what floating point numbers in JavaScript can represent. Use Number.MAX_VALUE to check if a number exceeds the JavaScript numerical limits.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript number max value
JavaScript Number Max Value
September 1, 2008 - It returns the maximum numeric value representable in JavaScript i.e "1.7976931348623157E+308". The following example demonstrates the usage of the JavaScript Number MAX_VALUE property.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-number-max_value-property
JavaScript Number.MAX_VALUE Property - GeeksforGeeks
August 5, 2025 - Number.MAX_VALUE represents the biggest possible numeric value of a positive number that can be represented in JavaScript. It is the maximum possible positive number representable in JavaScript within float precision.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-number-max_value-min_value-property
JavaScript Number MAX_VALUE & MIN_VALUE Property - GeeksforGeeks
July 11, 2025 - JavaScript Number.MAX_VALUE and Number.MIN_VALUE is used to represent maximum and minimum numeric values in javascript.
🌐
Educative
educative.io › answers › what-is-numbermaxvalue-in-typescript
What is Number.MAX_VALUE in TypeScript?
Any number value more than this is represented as infinity. Let's understand this better with a code example below: ... Line 2: We create a number variable and assign it the value of Number.MAX_VALUE.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › max
JavaScript Math max() - Find Maximum Value | Vultr Docs
November 27, 2024 - The Math.max() method in JavaScript is a straightforward yet powerful tool used to determine the maximum value among its given arguments. By accepting multiple numbers or an array of numbers (with a spread operator), this method evaluates and returns the largest number in the set, facilitating numerical comparisons directly in your code.
Top answer
1 of 3
7

There is actually no "native" HTML way outside a form post to avoid the faulty manual entry. You could do something like this (here jquery code):

$('input[type="number"]').on('change input keyup paste', function () {
  if (this.max) this.value = Math.min(parseInt(this.max), parseInt(this.value) || 0);
});

This code applies to all inputs of type number in case of keyboard input, pasting, changing a validation method that checks, whether a max value exists and if so Math.min() returns the lowest-valued number passed into it. If the value is not a number 0 is returned.

See a demo at JSFiddle

In Vanilla JavaScript the handler would look like this:

var numElement = document.querySelector('input[type="number"]')
numElement.addEventListener('change', validateMax);
numElement.addEventListener('input', validateMax);
numElement.addEventListener('keyup', validateMax);
numElement.addEventListener('paste', validateMax);

function validateMax() {
   if (this.max) this.value = Math.min(parseInt(this.max), parseInt(this.value) || 0);
}

See a demo of the vanilla version at JSFiddle

This handler should do the trick.

2 of 3
0

I don't think there is a solution directly with HTML; the max and min attributes only work when clicking the up arrow and down arrow keys. Check out the post in the references section for more information. The image below shows that the input does not change when the up arrow button is clicked, since the max attribute is 100:

In the solution below, when the input event of the <input> element is triggered, the data input is checked by checking the max attribute with the isValid() method. You can change the disabled property of the submit button according to the result returned by the isValid() method.

const inputElement = document.querySelector('input');

function isValid(value){
  if(parseInt(value) <= inputElement.getAttribute('max'))
    return true;
  return false;
}

inputElement.addEventListener('input', function () {
    if(isValid(this.value))
      console.log("true");
    else
      console.log("false");
});
<input type="number" max="100">


References
  • How can I limit possible inputs in a HTML5 "number" element?
🌐
W3Schools
w3schools.com › jsref › jsref_max.asp
JavaScript Math max() Method
❮ Previous JavaScript Math Object ... -10); let e = Math.max(1.5, 2.5); Try it Yourself » · The Math.max() method returns the number with the highest value....
🌐
Medium
medium.com › @qwertyiopasdffghjkl6578 › understanding-javascript-max-function-how-to-find-the-maximum-value-in-javascript-9dfa13b23a35
Understanding javascript max Function: How to Find the Maximum Value in JavaScript | by sacredherbs | Medium
March 17, 2025 - The Math.max() function in JavaScript returns the largest of the zero or more numbers passed as arguments. If no arguments are provided, it returns -Infinity. If any argument cannot be converted into a number, it returns NaN (Not-a-Number).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number
Number - JavaScript | MDN
The largest value a number can hold is 21023 × (2 - 2-52) (with the exponent being 1023 and the mantissa being 0.1111… in base 2), which is obtainable via Number.MAX_VALUE.
🌐
Built In
builtin.com › articles › javascript-array-max
3 Methods to Find the JavaScript Array Max | Built In
More on JavaScriptHow to Pass an Array From Java to JavaScript · In this traditional approach, we loop through each element in the array and compare it with a previously stored maximum value. If the current element is greater, we update our maximum. let numbers = [3, 7, 2, 8, 5]; let max = numbers[0]; // initialize to the first value for (let i = 1; i < numbers.length; i++) { if (numbers[i] > max) { max = numbers[i]; } } console.log(max); // Outputs: 8