Two different questions hide behind `[] == 0`

JavaScript’s truthiness test and its loose-equality test use different rules. An array is an object, and objects are truthy—even when the array contains nothing. So `if ([])` takes the “true” branch.

The `==` operator, however, may convert values before comparing them. In `[] == 0`, JavaScript first turns the array into a primitive value. An empty array becomes an empty string, `""`; then the comparison converts that string to the number `0`. The result is effectively `0 == 0`, which is true.

Strict equality stops the conversion

The `===` operator compares values without that kind of type conversion. An empty array is still an object, while `0` is a number, so `[] === 0` is false.

That distinction matters because a value’s behavior depends on the operation being used. “Truthy” does not mean “equal to true,” and an empty array’s truthiness does not prevent `==` from converting it during a comparison.

Why the distinction is useful

Loose equality can make compact code behave unexpectedly when values come from different types, such as user input or data decoded from a file. Using `===` makes the comparison’s type requirement explicit and avoids this particular conversion chain. The surprising part of `[] == 0` is not that an empty array is secretly zero; it is that `==` successively treats it as `""` and then as `0`.