为什么JavaScript中有[]!== []? [英] Why is [] !== [] in JavaScript?

查看:126
本文介绍了为什么JavaScript中有[]!== []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 []!== [] 在JavaScript中?

Why is [] !== [] in JavaScript?

我通读 https://developer.mozilla.org/en-US/docs/Web/JavaScript/ Equality_comparisons_and_sameness 但是我找不到任何解释这个的东西。

I read through https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness but I could not find anything that explains this.

编辑:
我不认为这个问题这个问题与我的完全相同。它询问 == 运算符,它只是表现得很疯狂。答案是我的问题的答案,但它不是同一个问题。

I don't think this question or this question is an exact duplicate of mine. It asks about the == operator which just behaves crazy. The answer is an answer to my question but it's not the same question.

推荐答案

这对两个数组文字进行了参考检查看看它们是否是同一个实例。您有两个文字的事实意味着您正在构建两个单独的数组,因此引用检查返回false。这将返回true:

That does a reference check on the two array literals to see if they are the same instance. The fact that you have two literals means that you are constructing two separate arrays, therefore the reference check returns false. This would return true:

var a = []
var b = a

//b === a

这是因为我们对同一个数组有两个引用。

This is because we have two references to the same array.

这篇关于为什么JavaScript中有[]!== []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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