The JavaScript snippet is as follows:
var a = [1, 2, 3],
b = [1, 2, 3],
c = [1, 2, 4]
a == b
a === b
a > c
a < c
As my understanding, because array is object and when you compare two objects using '==' or '===', you actually compare their reference. So a == b and a === b all returns false. Right?
Considering a > c and a < c comparison, I tried in Chrome and a > c returns false, a < c returns true. As I googled, "Arrays are compared lexicographically with > and <". Does that mean 'a > c' logically equals to:
for (var i = 0; i < Math.min(a.length, c.length); i++) {
if (a[i].toString() <= c[i].toString) return false;
}
return true;
Am I right? If not, can anyone help explain the mechanism behind it? thanks a lot.