[] == ![] evaluates to true

arrays, compare, javascript

Solution

`![]` evaluates to `false` because the reference is truthy. `[]` can be converted to a number ( 0 in this case ) which is a falsy value. Therefore: the condition passes as equal. If you did `===` it would be false.

Problem

I would like to know why the expression given in the title `[] == ![]` is evaluated to `true`. You cannot compare arrays as strings. I get that. If `[] == []` will evaluate to false because the references are different. Though if we have the following statement. ``` var arr = []; arr == arr // this evaluates to true simply because references are the same. ``` In order A == B to return `true` either A and B have to be `false` or `true`. A == !B in order to return `true` A can be `true` and B can be `false` or vice versa but in this case, A and B are the same values so I don't get it.

Original source

Related problems