denysdovhan / wtfjs

🤪 A list of funny and tricky JavaScript examples
http://bit.ly/wtfjavascript
Do What The F*ck You Want To Public License
34.75k stars 2.55k forks source link

[] == ![], they are not being both converted to numbers #163

Closed MVelez94 closed 3 years ago

MVelez94 commented 3 years ago

The spec says, in the ninth clause of https://www.ecma-international.org/ecma-262/#sec-abstract-equality-comparison, that if the right side is boolean, then the right side will become a number. That is; [] == ![] [] == false [] == 0 Now, the spec (in the eleventh clause of the aforementioned section) says that an object on the left side (this is, being x) compared to a number will reduce to ToPrimitive(x) == y. Calling ToPrimitive on an array A is the same as calling A.join(), and [].join() === "". That is; [] == 0 "" == 0 //true Thus, it is not true (as we are saying in our first example) that both operands get converted to 0 (moreover, they are not being both converted to numbers). Can I please send a PR if this reasoning is valid?

denysdovhan commented 3 years ago

Feel free to open a PR. Thanks!

denysdovhan commented 3 years ago

Fixed by #150

MVelez94 commented 3 years ago

@denysdovhan I don't think this one is fixed by #150 . May I please still open a PR with the explaination above? (I've been busy, sorry).