denysdovhan / wtfjs

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

more array equality #37

Closed futurist closed 7 years ago

futurist commented 7 years ago

Array equality is a monster in JS, think below:

[] == ''  // true
[] == 0  // true
[''] == ''  // true
[0] == 0  // true
[0] == ''  // ----> false
[''] == 0  // ----> true??

[null] == ''  // true
[null] == 0  // true
[undefined] == ''  // true
[undefined] == 0  // true

[[]] == 0  // true
[[]] == ''  // true

[[[[[[]]]]]] == ''  // true
[[[[[[]]]]]] == 0  // true

[[[[[[ null ]]]]]] == 0  // true
[[[[[[ null ]]]]]] == ''  // true

[[[[[[ undefined ]]]]]] == 0  // true
[[[[[[ undefined ]]]]]] == ''  // true

You should be very careful for above!

denysdovhan commented 7 years ago

Added! Thanks for reaching out!