DEV Community

Discussion on: Javascript Coercions (Conversions)

Collapse
 
southglitch profile image
SouthGlitch

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?

Collapse
 
khattakdev profile image
Arsalan Khattak

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