A database can hold a 64-bit unsigned ID larger than JavaScript’s maximum safe Number integer, 9,007,199,254,740,991. Reading that ID as a Number risks silently changing it. BigInt is JavaScript’s integer type for values beyond that boundary: it uses memory as needed rather than a fixed-width floating-point representation, preserving exact integer values. section 3.1.1 section 3.2
The first unsafe integer
In JavaScript, `9007199254740993` is a Number and does not retain that exact value; `9007199254740993n` is a BigInt and does. The `n` suffix matters before arithmetic begins: converting an already imprecise Number cannot recover the lost integer. BigInt also supports values such as `10n ** 100n`. section 3.2
Arbitrary precision describes the value’s ability to grow beyond a fixed machine word, not a required storage layout. ECMAScript leaves BigInt representation largely to implementations. V8 stores a large value across 64-bit chunks, reconstructing it by shifting higher chunks and adding lower ones; it keeps the sign separately. Growth therefore consumes more memory. section 3.2 section 3.5
Table 3.6 BigInt storage as 64-bit chunks
|
Chunk
|
Value
|
Binary (partial)
|
Purpose
|
|
0
|
3,584,949,746
|
...11010101110010
|
Lower 64-bits
|
|
1
|
6,692,605,942
|
...10001111110110
|
Higher 64-bits
|
The chunk table illustrates why a large BigInt need not fit in one 64-bit integer: its lower and higher portions occupy separate storage. section 3.2
Keep numeric types deliberate. JavaScript forbids arithmetic that mixes BigInt and Number, although comparisons work; Math methods operate on Numbers only. BigInt also addresses exact *integers*, not decimal fractions such as `0.1`: the proposed Decimal type targets exact base-10 arithmetic. Exactness has a cost—the stated BigInt performance penalty is 10–200×—so it is not a default replacement for ordinary Number arithmetic. section 3.5 section 3.1.1




