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.