var a = [], B = [];console.log (a==b);
What is the result of the console printing? The answer is: false.
Next look at the parsing:
The comparison of the original values is the comparison of the values:
They are equal when their values are equal (= =)
They are identical when their values and types are equal (= = =).
Unlike the original value, the object's comparison is not a comparison of values, but rather a comparison of references:
Even if two objects contain the same attributes and the same values, they are not equal
Even if the index elements of each of the two arrays are exactly equal, they are not equal
Give me a chestnut:
var o = {x:1}, p = {x:1}; // two objects with the same property o = = P // + = false: Two separate objects never equal var a = [], b = []; // two separate empty arrays a = = B // = = false: Two separate arrays are never equal
We usually refer to the object as a reference type (reference type), which distinguishes it from the basic type of JavaScript. Object values are references (reference), and comparisons of objects are reference comparisons: they are equal when and only if they reference the same base object.
Give me a chestnut:
var a = []; // defines a variable A that references an empty array var b = A; // variable B refers to the same array b[0] = 1; // Modify the referenced array with variable b a[0] // + 1: Variable A also modifies a = = = B // = = True : A and B refer to the same array, so they are equal
js-two empty arrays why not equal?