Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.3 — Numbers in Depth
JavaScript · Example 4 of 4 ES2020+

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.

01

Add the prices 19.99 and 5.01 so that the result is exactly 25 and log true when you compare it with 25.

02

Log whether Number("12px") is NaN using the correct test, and log the result of 100 / 0.

03

Log 2 to the power of 70 exactly.

Explain it without notes

01

Why does 0.1 + 0.2 not equal 0.3 in JavaScript, and how do you handle money?

02

What is NaN, why is NaN === NaN false, and how do you test for it?

03

What is Number.MAX_SAFE_INTEGER and what happens beyond it?

04

When would you use BigInt, and what are its limits?

BigInt: exact integers of any size ES2020+

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