I was reading Eloquent JS and came across this code which didn't make sense to me. I wasn't able to understand it as it was explained and was hoping someone could explain to me why the second console.log evaluates to the value it does.
Here's the code:
var listOfNumbers = [2, 3, 5, 7, 11];
console.log(listOfNumbers[1]);
// → 3
console.log(listOfNumbers[1 - 1]);
// → 2
Any ideas?
listOfNumbers[1 - 1]is the same aslistOfNumbers[0]