BigInt
easyComplete guide with examples and interview questions · 20 min
Say it out loud in an interview — clear, simple, no textbook wording.
If someone asks what BigInt is, I'd say it's JavaScript's answer to integers that are too big for the regular Number type. A Number is a 64-bit float, so it only keeps integers exact up to 2^53 − 1. Past that, Number.MAX_SAFE_INTEGER + 1 and + 2 both print 9007199254740992. BigInt stores arbitrarily large integers exactly — you just add an n: 9007199254740993n.
What interviewers probe most is that BigInt is deliberately strict: 1n + 1 throws a TypeError. The engine won't guess whether you wanted a Number or a BigInt result, so you convert one side explicitly first.
In senior rounds, expect the quirks: JSON.stringify(5n) throws, 5n / 2n is 2n (division truncates), and Math.sqrt(4n) throws because Math only takes Numbers. One elegant fix to know: BigInt.prototype.toJSON is honored by JSON.stringify, so a tiny prototype patch makes BigInts serializable — one of the rare cases where patching a built-in is officially acceptable.
Key takeaways
- •BigInt stores integers beyond Number.MAX_SAFE_INTEGER (2^53 - 1) with no precision loss
- •Mixing BigInt and Number in arithmetic throws a TypeError — convert one side explicitly first
- •BigInt division truncates — 5n / 2n is 2n, never 2.5n
- •JSON.stringify throws on BigInt — stringify with toString() first
- •0n === 0 is false but 0n == 0 is true; relational comparisons (<, >) mix types freely
Track your mastery
Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.
Sign in to save progress