Advertisement
Intermediate JavaScript, Numbers, Math & BigInt

Why does 9007199254740993n + 1 throw a TypeError, but 9007199254740993n + 1n does not?

Short answer

JavaScript deliberately disallows implicit mixing of BigInt and Number in arithmetic, because silently converting one to the other could quietly reintroduce precision loss (defeating the whole purpose of BigInt) — you must explicitly convert one side to match the other's type.

Save JavaScript mock interview
Advertisement
AModel answer
JavaScript deliberately disallows implicit mixing of BigInt and Number in arithmetic, because silently converting one to the other could quietly reintroduce precision loss (defeating the whole purpose of BigInt) — you must explicitly convert one side to match the other's type.
Example

9007199254740993n + 1; // TypeError: Cannot mix BigInt and other types 9007199254740993n + 1n; // 9007199254740994n -- works, both are BigInt

Real-world example
Catching a bug early where a regular number accidentally got combined with a BigInt ID without explicit conversion.
Likely follow-ups
  • How do you safely convert a BigInt to a Number when precision loss is acceptable?
Related topics