Please, can you explain me why the following lines of code, print letter E many times, instead of A,B,C,D,E ?
I don't understand what's going on. I've tried many things, but i get either errors, or undefined values.
var values = ['A','B','C','D','E'];
var myfunctions = [];
for (var i = 0;i < values.length;i++){
var letter = values[i];
console.log(letter);
myfunctions.push( function(){
console.log(letter);
});
};
for (var j = 0;j < values.length;j++){
myfunctions[j]();
};