#9: '0' == false vs '0' == ''
Topic: coercion · Difficulty: ★★
console.log('0' == false);
console.log('0' == '');Output
true false
Why
'0' == false first converts false to the number 0, then converts the string '0' to the number 0 too, so 0 == 0 is true. But '0' == '' compares two strings directly — when both operands are already strings, == never coerces at all, it just checks for exact character-by-character equality. '0' and '' are different strings, so that comparison is false, even though both would become falsy values if converted to booleans.
More coercion puzzles