BigInt is JavaScript’s integer type for values that may exceed the safe range of the ordinary number type. Use it when backend IDs, timestamps, financial data, scientific APIs, or cryptographic calculations can contain integers larger than Number.MAX_SAFE_INTEGER or smaller than Number.MIN_SAFE_INTEGER. It keeps those integer calculations precise instead of silently losing accuracy. section 2.4 section 2.4.1
Create a BigInt by appending n to an integer literal or by passing an integer string to BigInt(). A BigInt represents integers only: it has no floating-point form. section 2.4.1 section 2.4.2
Listing 2.2 Working with BigInt values
const previousMax = BigInt(Number.MAX_SAFE_INTEGER);
const noLongerUnsafe1 = previousMax + 1n;
const noLongerUnsafe2 = previousMax + 2n;
console.log(`The old maximum safe integer: ${previousMax}`);
console.log(`The old maximum plus 1 equals ${noLongerUnsafe1}`);
console.log(`The old maximum plus 2 equals ${noLongerUnsafe2}`);
Adding beyond the former maximum safe integer continues to produce distinct, exact values when every operand is a BigInt. section 2.4.1
Use BigInt with a few type rules in mind:
- Use basic arithmetic such as +, -, *, /, %, and **, but do not use unary +. section 2.4.2
- Do not mix number and bigint in one arithmetic expression; explicitly convert the value you need. section 2.4.2
- Expect division to discard a fractional part, because BigInt calculations remain integers. section 2.4.2
- Compare number and bigint values when needed; comparison expressions may contain both types. section 2.4.2
Keep arithmetic in one numeric type
A literal without n is a number, so adding it to a BigInt throws a TypeError. Write both values as BigInts instead: const max = 9007199254740991n; console.log(max + 10n); section 2.4.4 section 2.8
BigInt is mainly for behind-the-scenes calculation, not visual UI values. It is unsupported by Math methods and JSON.stringify(), and it does not automatically work with DOM APIs or CSS. Regular numbers remain the practical choice for animation, layout, styles, serialization, and values that stay within safe integer limits. section 2.4.3 section 2.4.4



