Skip to content

BigInt

BigInt is a numeric primitive that can represent integers larger than 2^53 - 1 (the maximum safe integer for Number).

Financial calculations, large IDs, and cryptographic operations often need numbers beyond Number.MAX_SAFE_INTEGER (9,007,199,254,740,991).

// Using n suffix
const big1 = 1234567890123456789012345678901234567890n;
// Using BigInt() function
const big2 = BigInt('1234567890123456789012345678901234567890');
const big3 = BigInt(42); // 42n
console.log(typeof big1); // 'bigint'
const a = 10n;
const b = 3n;
a + b; // 13n
a - b; // 7n
a * b; // 30n
a ** b; // 1000n
// Division truncates towards zero
a / b; // 3n (not 3.333...)
// Cannot mix with regular numbers
10n + 5; // TypeError!
10n + BigInt(5); // 15n ✅
Number(10n) + 5; // 15 ✅
10n === 10; // false (different types)
10n == 10; // true (loose equality works)
10n > 5; // true
10n < 20; // true
  • n suffix creates BigInt literals
  • Represents arbitrarily large integers
  • Cannot mix with regular Number in operations
  • Use BigInt() for conversion
  • Perfect for large IDs, financial calculations