What does console.log([1] == 1, [1] == '1', [] == '') output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-82.js
1console.log([1]==1,[1]=='1',[]=='')
Coercion
Answer & explanation
Console output
true true true
Why
Loose equality converts the array to a primitive via toString: [1] becomes "1" and [] becomes "". Then [1] == 1 compares "1" to 1 (string coerces to number 1, true), [1] == "1" is "1" == "1" (true), and [] == "" is "" == "" (true). Single-element arrays masquerade as their lone element under ==.