SyntaxStudy
Sign Up
JavaScript BigInt: Arbitrary-Precision Integers
JavaScript Intermediate 8 min read

BigInt: Arbitrary-Precision Integers

BigInt: Arbitrary-Precision Integers

The BigInt type, introduced in ES2020, allows JavaScript to represent and operate on integers of arbitrary size, removing the 2^53 − 1 ceiling imposed by the Number type. It is essential for cryptography, working with database IDs that exceed safe integer range, and any domain requiring exact large-integer arithmetic.

Creating BigInt Values

Append n to an integer literal (9007199254740992n), or call BigInt(value) with a number or numeric string. You cannot use a float literal — 3.14n is a syntax error.

Arithmetic

BigInt supports +, -, *, / (integer division), %, and **. You cannot mix BigInt and Number in arithmetic — you must explicitly convert one side.

Comparisons

BigInt and Number can be compared with == (loose equality, which coerces) and with <, > etc., but not with === across types.

Example
const big = 9007199254740993n;
console.log(big);                  // 9007199254740993n
console.log(typeof big);           // 'bigint'
console.log(big + 1n);             // 9007199254740994n
console.log(big * 2n);             // 18014398509481986n
console.log(10n / 3n);             // 3n  (no remainder)
console.log(10n % 3n);             // 1n
console.log(10n == 10);            // true  (loose)
console.log(10n === 10);           // false (strict)
const fromNumber = BigInt(Number.MAX_SAFE_INTEGER);
console.log(fromNumber + 1n);      // 9007199254740992n
Pro Tip

Never store BigInt values in a JSON payload directly — JSON.stringify throws a TypeError. Convert to string first with .toString() and parse back on the receiving end.