1

JavaScript uses a fixed number of bits, 64 of them, to store a single number value. There are only so many patterns you can make with 64 bits, which means that the number of different numbers that can be represented is limited. With N decimal digits, you can represent 10^N numbers. Similarly, given 64 binary digits, you can represent 2^64 different numbers, which is about 18 quintillion (an 18 with 18 zeros after it).

  • 1
    Does this answer your question? [Number of bits in Javascript numbers](https://stackoverflow.com/questions/2802957/number-of-bits-in-javascript-numbers) – Peter B Sep 14 '21 at 22:49
  • Specifically, the largest non-big integer is `Number.MAX_SAFE_INTEGER`; the largest floating point value `Number.MAX_VALUE`. – Amadan Sep 14 '21 at 23:04

1 Answers1

1

Javascript traditionally stores numbers as a 64 bit floating point with a 52 bit mantissa an 11 bit exponent and the sign is 1 bit. Effectively this means that

Integers are accurate up to 15 digits. -- w3schools.com

Now with ES6 the BigInt proposal has been finalized, so you can access a second type of number when dealing with integers that may be larger than 52 bits. There also exist some libraries for operations on large numbers provided as strings.

  • 1
    Prefer linking to [MDN](https://developer.mozilla.org/en-US/) documentation for javascript references. see: [Why not w3schools.com?](https://meta.stackoverflow.com/questions/280478/why-not-w3schools-com). Relevant to your answer: [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) – pilchard Sep 14 '21 at 23:19
  • @pilchard in this instance, I've linked to both. w3schools actually had a cleaner summary than MDN. Plus its "datedness" is desirable here – That Realty Programmer Guy Sep 15 '21 at 06:31