{} + [] - why it is 0 or [object Object]?

后端 未结 4 872
情深已故
情深已故 2020-12-31 04:45

If you open a JS Console in your browser (in my case Chrome) and type:

{} + []

you will get 0, but when you type

console.lo         


        
4条回答
  •  一整个雨季
    2020-12-31 05:00

    Empty object as {} returns "[object Object]" when you call its toString() method. Empty array returns "" when you call its toString() method. Thus, console.log({} + []) will output "[object Object]"

提交回复
热议问题