Re:Teaching the Unfortunate Parts
by thaumasiotes on Tuesday December 29, 2020 @01:36AM
(#25567348)
So then what should this code produce?
That code would (assuming an integer value; the question is interesting without reference to the implementation of JavaScript) return arr[0], the first element. Don't think of arr[-1] as indexing the array with a negative number that might have been a positive number. Think of array access from the front, arr[ ], and array access from the back, arr[- ], as separate operations with separate syntax, each of which can accept only nonnegative numbers. arr[i] is of the first type, so you get the first element counted from the front.
[ Parent
| on HN ]
There are no comments on this comment yet.