🟑 MediumType CoercionπŸ’» Output Question

Falsy values comparison

πŸ’‘

Hint

Coercion is not transitive: false==0, false=="", but 0!="0" in string context.

What does this output?

console.log(false == 0);
console.log(false == '');
console.log(false == '0');
console.log(0 == '');
console.log(0 == '0');
console.log('' == '0');

Correct Output

true
true
true
true
true
false

Why this output?

Explanation: All combinations of false/0/"" coerce to 0 and are equal. But "0" as a string and "" as a string are NOT equal to each other β€” string comparison, no coercion needed.

Key Insight: Coercion is not transitive: false==0, false=="", but 0!="0" in string context.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumNaN comparisonβ†’πŸ”΄ HardObject to primitive coercionβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz