I was watching Javascript Essentials by Travis Tidwell where he explained this piece of code:
(function() {
var messages = ['hello', 'there'];
for (var i in messages) {
setTimeout(function() {
console.log(messages[i]);
}, 10);
};
})();
It echoes 'there' twice in the console, but I still don't understand exactly why. Could somebody go through this piece of javascript with me step by step?