Skip to solution
mediumFrontend

What is BigInt?

214 views
01

Understand the problem

Question presented to candidate: "If you need to work with an integer larger than Number.MAX_SAFE_INTEGER, what actually goes wrong if you just use a regular number, and how does BigInt fix it?"

What a strong answer should cover:

  • 📌 Interview term: BigInt — a distinct primitive type representing arbitrarily large integers exactly, written with a trailing n (123n) or via BigInt(123), with no upper bound and no precision loss, unlike regular numbers.
  • 📌 Interview term: the real, direct answer to the prompt — verified directly: a value beyond Number.MAX_SAFE_INTEGER (9007199254740991) written as a regular Number genuinely loses precision (rounds to the nearest representable double), while the identical value written as a BigInt literal genuinely preserves it exactly.
  • 📌 Interview term: BigInt and Number cannot mix implicitly — verified directly: adding a BigInt and a Number directly (1n + 1) genuinely throws a real TypeError — an explicit conversion (1n + BigInt(1), or Number(1n) + 1) is genuinely required, a deliberate design choice preventing silent precision loss from sneaking into BigInt arithmetic.
  • 📌 Interview term: BigInt division truncates — verified directly: 7n / 2n genuinely produces 3n, not 3.5n — BigInt division always rounds toward zero, since a BigInt can never represent a fraction at all.
  • A precise answer names that loose equality (==) genuinely works across BigInt/Number (1n == 1 is true, verified directly), while strict equality (===) genuinely does not (1n === 1 is false, since they are different types) — the same type-vs-value distinction covered in this bank's own == vs. === question.

Clarifying questions expected:

  • None — this is a definitional/technical question; directly answering what specifically breaks with a regular Number (silent precision loss, not a crash) is the strong signal.

Code / implementation expected: Yes — the direct side-by-side precision-loss comparison between a large Number and the equivalent BigInt is the clearest, most convincing demonstration.

bigint
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every precision and arithmetic claim below was actually run in Node.

1. Why This Even

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: a Number beyond MAX_SAFE_INTEGER silently loses precision while the equivalent BigInt preserves it exactly
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 109 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track