The JavaScript BigInt object
A BigInt is a primitive for integers too large for the regular Number type to hold safely (beyond about 9 quadrillion). Write one with an n suffix (9007199254740993n) or with BigInt(value). You can't mix BigInt and Number in arithmetic without converting one.
Overview
BigInt exists because the normal Number type can only represent integers exactly up to Number.MAX_SAFE_INTEGER (about 9 quadrillion, or 253−1). Beyond that, numbers lose precision: 9007199254740993 quietly becomes ...992. BigInt handles arbitrarily large integers with full precision, which matters for big IDs (like database or Twitter/X snowflake IDs), high-precision timestamps, and cryptography.
You create one in two ways: a numeric literal with an n suffix (123n, 9007199254740993n), or the BigInt() function (BigInt("123"), BigInt(123)). Arithmetic works as you'd expect (10n * 10n is 100n), and the result is always a BigInt.
The big rule: you can't mix BigInt and Number in the same operation. 1n + 1 throws a TypeError. Convert explicitly first (1n + BigInt(1) or Number(1n) + 1), choosing whether you want a BigInt or Number result. Also note BigInt is integer-only (no decimals; 5n / 2n is 2n), JSON.stringify() can't serialize it (convert to a string first), and typeof a BigInt is "bigint". For everyday numbers, stick with Number.
Syntax
const big = 9007199254740993n; // n suffix
const also = BigInt("123"); // from a string
10n * 10n // 100n
typeof 10n // "bigint"
1n + BigInt(1) // 2n (can't mix with Number directly)
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const unsafe = 9007199254740993; // Number loses precision
const safe = 9007199254740993n; // BigInt keeps it
document.getElementById('out').textContent =
'Number: ' + unsafe + '\n' +
'BigInt: ' + safe + '\n' +
'2n ** 64n = ' + (2n ** 64n);
</script>
Best practices
- Use
BigIntonly when integers exceedNumber.MAX_SAFE_INTEGER. For ordinary numbers, use Number. - Never mix BigInt and Number in one operation. Convert one with
BigInt()or Number() first. - Remember BigInt is integer-only; there are no fractional BigInts.
- Convert to a string before JSON.stringify(), which can't serialize BigInt.
Frequently asked questions
What is a BigInt in JavaScript?
n suffix (123n) or BigInt(value).Why can't I add a BigInt and a Number?
TypeError to avoid silent precision loss. Convert one first: 1n + BigInt(1) or Number(1n) + 1.When should I use BigInt?
Can BigInt have decimals?
5n / 2n is 2n (the fractional part is dropped).