HardType Coercion💻 Output Question

Array coercion with plus operator

💡

Hint

Arrays convert to their string representation for coercion: [] → "", [1,2] → "1,2".

What does this output?

console.log([] + []);
console.log([] + {});
console.log(+[]);
console.log(+[42]);

Correct Output


[object Object]
0
42

Why this output?

Explanation: []+[]: ""+"" = "". []+{}: ""+"[object Object]". +[]: []→""→0. +[42]: "42"→42.

Key Insight: Arrays convert to their string representation for coercion: [] → "", [1,2] → "1,2".

More Type Coercion Output Questions

EasyPlus operator: string concat vs numeric addMediumLoose equality edge cases with nullEasytypeof for common valuesMediumTruthy and falsy — empty array and object are truthy

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz