whatstheoutput_

#8: [] == false

Topic: coercion · Difficulty: ★

console.log([] == false);

Output

true

Why

Loose equality between an object and a boolean first converts the boolean to a number: false becomes 0. Then [] (an object) is converted to a primitive, which for arrays means joining their elements into a string — an empty array joins to the empty string ''. Now it's '' == 0, a string vs a number, so '' is converted to a number too, giving 0 == 0, which is true. Every step quietly changes the type until both sides finally agree.

More coercion puzzles

Play today's puzzle →