Course contentsShow
← JavaScript
Lesson 129 of 2,7234. Working with NumbersFree lesson

BigInt Arithmetic Operations

Use +, -, *, /, %, and ** with BigInt values while understanding division truncates toward zero.

BigInt Arithmetic Operations

You'll learn: How to perform basic math operations with BigInt values and understand their unique behavior.

Now that you can create BigInt values, you can do arithmetic with them! BigInt supports the same basic operators as regular numbers: addition (+), subtraction (-), multiplication (*), division (/), remainder (%), and exponentiation (**).

How BigInt Arithmetic Works

BigInt operations work just like Number operations, but with one critical difference: division always truncates toward zero, giving you only the whole-number part of the result—no decimals allowed.

const a = 100n;
const b = 30n;

console.log(a + b);   // 130n
console.log(a - b);   // 70n
console.log(a * b);   // 3000n
console.log(a / b);   // 3n  (not 3.333...)
console.log(a % b);   // 10n (remainder)
console.log(a ** 2n); // 10000n

Division Truncates Toward Zero

When you divide BigInt values, JavaScript removes any fractional part. It always moves toward zero:

console.log(17n / 5n);   // 3n (not 3.4)
console.log(-17n / 5n);  // -3n (not -3.4)

Think of it like counting physical objects: if you divide 17 apples among 5 people using whole apples only, each gets 3, with 2 left over.

Important Restrictions

You cannot mix BigInt and Number in operations:

// These will cause errors:
// 10n + 5
// 100n * 2

Key Takeaway: BigInt supports +, -, *, /, %, and ** operations, but division always truncates toward zero (no decimals), and you cannot mix BigInt with regular Number values.