It seems like there is no maximum limit to a BigInt as per spec, which makes sense considering BigInts are supposed to be arbitrary-precision integers, whose "digits of precision are limited only by the available memory of the host system".
As for v8 specifically, according to this article on the v8 blog, the precision of BigInts are "arbitrary up to an implementation-defined limit". Unfortunately, I couldn't find any further information on how the limit is determined. Maybe someone else would be able to shed light on this based on these v8 BigInt implementation notes?
That said, based on the aforementioned articles, there doesn't seem to be a specific maximum value/size for a BigInt. Rather, it is likely determined based on the available memory on the system in some way.
Answer from zwliew on Stack OverflowVideos
» npm install big-integer
It seems like there is no maximum limit to a BigInt as per spec, which makes sense considering BigInts are supposed to be arbitrary-precision integers, whose "digits of precision are limited only by the available memory of the host system".
As for v8 specifically, according to this article on the v8 blog, the precision of BigInts are "arbitrary up to an implementation-defined limit". Unfortunately, I couldn't find any further information on how the limit is determined. Maybe someone else would be able to shed light on this based on these v8 BigInt implementation notes?
That said, based on the aforementioned articles, there doesn't seem to be a specific maximum value/size for a BigInt. Rather, it is likely determined based on the available memory on the system in some way.
The maximum size of a BigInt in webkit is defined as such
// The maximum length that the current implementation supports would be
// maxInt / digitBits. However, we use a lower limit for now, because
// raising it later is easier than lowering it.
// Support up to 1 million bits.
static constexpr unsigned maxLength = 1024 * 1024 / (sizeof(void*) * bitsPerByte);
The size of void* is platform dependent, 8 on 64 bit systems.
So there's your answer right? Should be 16384 bits.... (-1 for the sign). But I can't create anywhere near that large a number in console.
MDN doc
BigIntis a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with theNumberprimitive and represented by theNumber.MAX_SAFE_INTEGERconstant.BigIntcan be used for arbitrarily large integers.
Difference:
BigIntcannot be used with methods in the built-inMathobject and cannot be mixed with instances ofNumberin operations- Because coercing between
NumberandBigIntcan lead to loss of precision, it is recommended to only useBigIntwhen values greater than 2^53 are reasonably expected and not to coerce between the two types.
The differences between BigInt and Number:
Number |
BigInt |
|
|---|---|---|
| Safe Range | Number.MAX_SAFE_INTEGER; loses precision outside of this range |
Extremely large integers |
| Math operations | Supports the Math object |
Basic arithmetic operations: + * - % ** |
| Decimal vs. Integer support | Integers and decimals, e.g 1.00, 2.56 |
Only integers, e.g 1n, 2n. 5n / 2 === 2n |
| Syntax | No special syntax | Append n to the end of a number literal or use new BigInt('100') |
| Type Conversion | Automatically converts Number to BigInt in operations |
Requires explicit conversion to Number for arithmetic involving Number values |
| JSON | Supported by default | Not serializable by default |
Use BigInt when you need to work with extremely large integers or require precise integer arithmetic without any loss of precision.