Why is [] == false
is true
Because arrays behave oddly when compared to primitive values.
In particular, when you compare any non-boolean to a boolean, the boolean is handled as a number. Then, when you compare a number to an object the object is converted to a primitive - which stringifies the array before again comparing it to the number. Now, that string is converted to a number so that they can be compared:
[] == false
[] == 0
"" == 0
0 == 0
Similarly, you can try
[1] == true
[1] == 1
"1" == 1
1 == 1
or
[2] == true
[2] == 1
"2" == 1
2 == 1
but just []
evaluates to true?
Because any object is truthy.