πŸ”΄ HardType CoercionπŸ’» Output Question

Tricky array coercion

πŸ’‘

Hint

Arrays coerce to strings via .join(","). []==![] is true β€” one of JS's most infamous "wat" moments.

What does this output?

console.log([] == ![]);
console.log([] == false);
console.log(+[]);
console.log(+[1]);
console.log(+[1,2]);

Correct Output

true
true
0
1
NaN

Why this output?

Explanation: []==![]: ![] is false ([] is truthy). []==false. [].toString()="" then +"" =0. false→0. 0==0 → true.
[]==false: [].toString()="", +""=0, false→0, 0==0→true.
+[]: []β†’""β†’0.
+[1]: [1]β†’"1"β†’1.
+[1,2]: [1,2]β†’"1,2"β†’NaN.

Key Insight: Arrays coerce to strings via .join(","). []==![] is true β€” one of JS's most infamous "wat" moments.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumFalsy values comparisonβ†’πŸŸ‘ MediumNaN comparisonβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz