I have a question about one of your problems in the “Accessing Adjacent Items” workbook.
For the following:
let array = [1, 2, 3, 4, 5]
let i = 2
let neighborIndex = i + 1console.log(array[i] + ‘,’ + array[neighborIndex])
Why did they say the output of this code is:
3, 4
…?
Why does the new variable declaration
let i = 2
…automatically refer to the array index, even though the “let i = 2” code was not part of the array declaration?
Does the variable “i” always refer to the last array referenced, or something…?
If so, I suppose we should never use the “i” as a variable when coding, unless using it as an index reference?
Thanks in advance.