Q: How two arrays that look exactly the same can be different? Look at this JS code:


var st, ary, ary1, ary2;
ary  = [["a","b","c"], ["d","e","f"]]; // 2D array
ary1 = ary[1];
st   = "d,e,f"; ary2 = st.split(',');
st   = typeof(ary1) + " " + ary1.length + " " + ary1 + '\n';  // I put all output into a string 
st  += typeof(ary2) + " " + ary2.length + " " + ary2 + '\n'; // for a single display
st  += (ary1[0]==ary2[0])+'\n';
st  += (ary1==ary2);

console.log(st);
.as-console-wrapper { max-height: 100% !important; top: 0; }


Output:

object 3 d,e,f
object 3 d,e,f
true
false

... Same but different! Why's that?

A: Because == checks if its actually the same object by checking the reference. It does not care about the content of the object. You could even deep clone the array to another array, it would still be different.
Consider this:
Person object1 = new Person("1", "Thomas", "Meier");
Person object2 = new Person("1", "Thomas", "Meier");
Person object3 = object1;

System.out.println(object1 == object2);
// Output: false
System.out.println(object1 == object3);
// Output: true


A: Because they have different links. When you have created an array the var got a link. When you try to compare two arrays, js compares links.
