Do you know what will be the output of this code?
JavaScript
console.log(false == '0');
Show answer and explanation
The answer is true.
In this situation, the abstract equality comparison algorithm is used, which is also called the type-coercing equality check. What it does is converting the values as long as possible, until they match in type and can be compared strictly.
In this case, the following steps are performed:
// 1st step
false == '0'
// 2nd step
Number(false) == '0' -> 0 == '0'
// 3rd step
0 == '0' -> 0 == Number('0')
// 4th step
0 == 0 -> 0 === 0 -> true