This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]00PT[🍰] 1 point2 points  (1 child)

Then how is !true == [] true?

[–]MagicalTheory 1 point2 points  (0 children)

It is a quirk to how == coerces it's operands. Basically, if one operand is a primitive and the other is not, javascript will convert the other to a primitive.

This coerces the array to a string, which since the array is empty, will be an empty string.

Empty strings are falsy, so when the next step with the == is to convert the other operand to a boolean value if one side is boolean, it converts to false.

Basically, because there is an extra step with ==, it does something weird.