Interview Q&A / JavaScript

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is BigInt in JavaScript and when would you use it?

SHORT ANSWER

BigInt is a primitive for whole numbers of any size, written with an n suffix like 123n. Use it when values pass Number.MAX_SAFE_INTEGER (2^53 - 1), such as large IDs. It cannot be mixed with regular numbers.

Explain it simply

A normal JavaScript number is a 64-bit float. It can only represent whole numbers exactly up to 9,007,199,254,740,991. Past that, neighbouring integers start to collapse into the same value, like a cheap calculator that rounds big totals.

BigInt removes the ceiling. Add n to a literal or call BigInt("..."). Arithmetic works, but you cannot mix BigInt and Number in one expression: JavaScript throws a TypeError instead of guessing.

Division drops the fraction (7n / 2n is 3n), and JSON.stringify cannot serialise a BigInt without help.

Example

js
console.log(Number.MAX_SAFE_INTEGER);            // Output: 9007199254740991
console.log(9007199254740992 === 9007199254740993); // Output: true
console.log(9007199254740992n === 9007199254740993n); // Output: false
console.log(typeof 10n);                          // Output: bigint
console.log(String(7n / 2n));                          // Output: 3
console.log(10n > 5);                             // Output: true
console.log(10n == 10);                           // Output: true
console.log(10n === 10);                          // Output: false

10n + 5 would throw a TypeError.

What to say in the interview

"BigInt is the seventh primitive, for integers beyond 2^53 - 1 where Number loses precision, for example 64-bit database IDs or exact factorials. It cannot be mixed with Number in arithmetic, division truncates, and it is not JSON-serialisable by default."

Common mistakes

  • Mixing 5n + 1 and expecting a result. It throws.
  • Using BigInt for decimals. It only holds integers.

#javascript#types

Related questions

Practise more JavaScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open JavaScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.