Destructuring Tweets – Episode 4 – Summing Up
console.log(0.1 + 0.2); console.log(0.1 + 0.2 == 3); console.log(0.1 + 0.2 === 3);
What we have here seems to be relatively simple at first glance. The author creates three console logs. The first features an addition of 0.1 and 0.2, and the second and third compare the result to 0.3 with two different operators.
The first operator
== is called “Equal”, the second
=== “Strict Equal”. Both return a boolean value, indicating whether the first and second statement is the same. So, a
console.log either outputs
Well, the output is easy here, isn't it? It should be:
Surprisingly enough, none of these is correct!
The two falses are evident in that context. Since the first output is this odd (pun intended) number, the addition is indeed not equal to
We end up with the fundamental question of why the hell does
0.1 + 0.2 equal