Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why is 0.1 + 0.2 == 0.3 false in JavaScript?

Do you know what will be the output of this code?

JavaScript
console.log(0.1 + 0.2 == 0.3);
Show answer and explanation

The answer is false.

This is not a JavaScript quirk but actually based on floating point arithmetic. Some decimal numbers simply can’t be represented accurately by computers and some decimal numbers can’t be added up accurately. This is the case in this situation.

0.1 + 0.2 -> 0.30000000000000004

And 0.30000000000000004 is never equal to 0.3.

Take the full quiz Next question →

More Numbers questions

  1. Why is typeof NaN "number" in JavaScript?
  2. Why does 018 - 015 equal 5 in JavaScript?
  3. Why is Math.max() < Math.min() true?
  4. What is -7 % 3 in JavaScript?
  5. Why does indexOf not find NaN but includes does?

Related topics