Command Palette

Search for a command to run...

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

Where exact whole numbers end

The literal 9007199254740993 can't be stored, so it is rounded to the nearest storable number before your code even runs.

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?

Where exact whole numbers end

Console

(nothing was printed)

Expected console output

9007199254740991
9007199254740992
9007199254740992
9007199254740992
true
false