【发布时间】:2018-08-23 03:29:38
【问题描述】:
我知道问这个问题很愚蠢,但谁能告诉我 为什么 === 和 == 为跟随而给出错误。
x=[[1,2]];
console.log(x[0]===[1,2]);
console.log(x[0]==[1,2]);
这里 typeof(x[0]) 和 typeof([1,2]) 也是一样的,那为什么给假呢?
【问题讨论】:
标签: javascript
我知道问这个问题很愚蠢,但谁能告诉我 为什么 === 和 == 为跟随而给出错误。
x=[[1,2]];
console.log(x[0]===[1,2]);
console.log(x[0]==[1,2]);
这里 typeof(x[0]) 和 typeof([1,2]) 也是一样的,那为什么给假呢?
【问题讨论】:
标签: javascript
因为它们在内存中是不同的值。
x=[[1,2]];
console.log(x[0]===[1,2]); // Here you're creating a new array in memory
console.log(x[0]==[1,2]); // Here you're creating a new array in memory
var y = x[0]; //Same value in memory
console.log(x[0]===y);
console.log(x[0]==y);
【讨论】: