Is this defined by the language? Is there a defined maximum? Is it different in different browsers?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JavaScript has two number types:
NumberandBigInt.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: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:
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.
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.