What is [] + [] in javascript

后端 未结 2 354
执念已碎
执念已碎 2021-01-06 06:26

What are the values of []+[], []+{}, {}+[], {}+{}? And How?

This my console log

>{} + {}
>NaN
>[] + []
>\'\'
>{} + []
>0
>[] + {         


        
2条回答
  •  Happy的楠姐
    2021-01-06 07:14

    The + operator concats strings. So it attempts to convert the objects and arrays to strings.

    {} converts to '[Object object]', and [] converts to ''.

    EDIT: I can't explain why {} + [] is 0 and why ({}) + [] is "[object Object]".

提交回复
热议问题