The ==
operator forces a type cast. []
as boolean is false
. Why doesn't the same happen with eg. "a" == false
? Basically, the numeric value of []
is 0
, while the numeric value of "a"
is NaN
. Predictably, "0" == false
is true
:)
On the other hand, in the second case, you're basically just checking if []
exists ("isn't null"). There is no casting to boolean.