I accidentally typed:
var x = [1, 2, 3, 4];
console.log(x[1, 2]); //this will log 3
console.log(x[3, 1]); //this will log 2
It turns out I can use any number of comma-separated indices to refer to array elements. The last index is always used. If the last index is larger than the array, undefined
is the result.
Why does this syntax work?