I understand closures but I don't understand how this example works:
for (var i=1; i<=5; i++) {
setTimeout( function timer(){
console.log( i );
}, i*1000 );
}
In this example it logs 6 six times with a value of six. I understand this is due to closures. However, I don't understand how. Any help would be appreciated.