JavaScript · Senior · Question 30 of 75
What happens with 10n + 1?
- ✓Correct answer:
TypeError: you can't mixBigIntandNumberin arithmetic - 2The result is
11n: the number is converted toBigIntautomatically - 3The result is
11: theBigIntbecomes a number automatically
Explanation
Implicit mixing is forbidden to avoid losing precision. Be explicit: 10n + BigInt(1) or Number(10n) + 1. BigInt is needed for integers larger than Number.MAX_SAFE_INTEGER (2^53 − 1): IDs, cryptography. JSON.stringify doesn't support it.