whatstheoutput_

#2: 0.1 + 0.2 === 0.3

Topic: numbers · Difficulty: ★

console.log(0.1 + 0.2 === 0.3);

Output

false

Why

JavaScript numbers are IEEE-754 double-precision floats, stored in binary. 0.1 and 0.2 have no exact binary representation — like 1/3 has no exact decimal one — so each is stored slightly off. Their sum is 0.30000000000000004, which is not exactly 0.3, so the strict comparison is false. When comparing float results, compare against a tolerance instead: Math.abs(a - b) < Number.EPSILON.

More numbers puzzles

Play today's puzzle →