As you can see in this javascript equality table, javascript equality transitivity is weird.
I understand most of the results of the table, but I have a question regarding the following comparison:
[] == true // false
[] == false // true
!![] == true // true
!![] == false // false
But also:
if ([]) {
// this code will run
}
if (!![]) {
// and of course this too
}
Why? Is this another extremly bad part? Have this a reasonable explanation?
[] == falsein your console :-P==, it needs to convert both operands to the same type. So what it does is converts[]to a string ('') and then to a number (0). It then convertsfalseto a number (0), then compares them. I'm still trying to figure out why!![]is true when[] == falseis also true.!![] == []is false. Please use===orlength,typeof foo === "undefined".(!![]) === ([] == false)is true :)