对象和数组的添加 [英] Objects and arrays addition

查看:114
本文介绍了对象和数组的添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释如何评估以下结果吗?

Can anyone explain to me how the results of the following was evaluated?

{} + {} // NaN
[] + {} // "[object Object]"
{} + [] // 0
[] + [] // ""


推荐答案

以下是对此的完整解释,检查

Here is a full explanation of this, check it.

并注意 {} + {} 如果您直接在控制台中执行 NaN ,因为 {} 被认为是一个块而不是一个对象。

And note {} + {} be NaN if you execute it directly in the console because {} is thought of a block rather than an object.

({} + {})应为'[object Object] [object Object]'

真正的结果是

The real result is:

console.log({}+{}) // '[object Object][object Object]'
console.log([]+{}) // '[object Object]'
console.log({}+[]) // '[object Object]'
console.log([]+[]) // ''

这篇关于对象和数组的添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆