Integers above 2^53 as a Number: are all their digits still there? BigInt (123n) holds them exactly, however big. Then try mixing one with a Number, or…
Why it matters
Ids from an API (Discord, Twitter, a database) are often 18 to 19 digits. Parsed as a Number, their last digits break silently and two different users can "become the same": a bug that is very hard to trace. Know the 2^53 limit and BigInt’s rules, and your big integers stay right.
The key idea
A Number is accurate up to 2^53; above it, use BigInt
Common mistakes
A big id from an API parsed as a Number Its last digits break above 2^53, and two different ids can become ===. Receive and keep it as a string (or a BigInt) from the start.
Mixing BigInt and Number1n + 1 throws a TypeError. Convert yourself: 1n + BigInt(1), or Number(1n) + 1 when the number is small.
JSON.stringify of a BigInt It throws a TypeError. Turn it into a string first (String(x), or a replacer), then BigInt(text) on the other side. That is why ids are sent as strings.
Try it in this playground
Add an n One letter turns a Number into a BigInt: both ids stay whole.
Pass MAX_SAFE_INTEGER 9007199254740992 + 1 with Numbers: the result misses the exact one.
Mix a BigInt and a Number10n + 1: the engine’s own TypeError.
Send a BigInt as JSONJSON.stringify throws a TypeError; String(hasil) carries every digit.