DEV Community


Discussion on: Javascript Coercions (Conversions)

southglitch profile image

I still don't get why [] == ![] is true.
[] is evalueted as an empty string, from there is converted to a 0, 0 should be equal to false, !false is true. So ![] shouldn't be true?

khattakdev profile image
Arsalan Khattak Author

Here's how it works

[] == ![]
0 == 0   // (Number([]) and Number(![]) both are equal to 0)
Enter fullscreen mode Exit fullscreen mode

Once both are 0,
Double Equals
And strict equality is pretty straight forward, if the values and types are the same, returns true