BigInt: exact integers of any size
The last line throws on purpose: BigInt and number can't be mixed in arithmetic.
Every JavaScript number is a 64-bit floating-point value, which is why 0.1 + 0.2 isn't exactly 0.3, why NaN and Infinity exist, and why whole numbers above 2^53 − 1 need BigInt.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Add the prices 19.99 and 5.01 so that the result is exactly 25 and log true when you compare it with 25.
Log whether Number("12px") is NaN using the correct test, and log the result of 100 / 0.
Log 2 to the power of 70 exactly.
Explain it without notes
Why does 0.1 + 0.2 not equal 0.3 in JavaScript, and how do you handle money?
What is NaN, why is NaN === NaN false, and how do you test for it?
What is Number.MAX_SAFE_INTEGER and what happens beyond it?
When would you use BigInt, and what are its limits?
Console
(nothing was printed)Expected console output
18446744073709551616n
9007199254740994n
3n
15n
false true
11
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions