I do understand the javascript closure as I think and I did a lot of small programs with it but in this code what I didn't understand is When I call the functions in the array why they are printing out different values of "i" aren't they suppose to refer to the same "i"?
function makeFunctionArray() {
const arr = []
//let i = 0
for (let i = 0; i < 5; i++) {
arr.push(function () { console.log(i) })
}
//console.log(i)
return arr
}
let functionarr = makeFunctionArray()
functionarr[0]() //print out 0
functionarr[2]() //print out 2
functionarr[1]() //print out 1