引用(复合)类型,相等问题,详见实例
//引用类型 相等问题 //两个空的新对象 指向的 是不同的 地址 console.log( {}==={} ); //false //指向 同一个 对象 let obj1 = { a: 1}; let obj2 = obj1; console.log(obj1 === obj2); //true //引用类型 套 引用类型 let obj3 = { a: 1, children: { b: 2, c: 3 } } let obj4 = obj3.children; let obj5 = { b: 2, c: 3 } console.log(obj4 === obj5); //false console.log(obj3.children === obj4); //true let obj6 = { a: 1, children: [ 2, 3 ] } let oArr7 = obj6.children; let oArr8 = [ 2, 3 ]; console.log(oArr7 === oArr8); //false console.log(obj6.children === oArr7); //true //数组同理 console.log([] === []); //false let arr1 = [1, 2]; let arr2 = arr1; console.log(arr1 === arr2); //true let arr3 = [ 0, [2, 3] ]; let arr4 = arr3[1]; let arr5 = [2, 3]; console.log(arr4 === arr5); //false console.log(arr3[1] === arr4); //true let arr6 = [ 0, { a: 2, b: 3}]; let aObj7 = arr6[1]; let aObj8 = { a: 2, b: 3}; console.log(aObj7 === aObj8); //false console.log(arr6[1] === aObj7); //true