As a beginner, I find myself struggling to understand the code snippet below.
for (var i=1; i<=5; i++) {
console.log('ooo');
setTimeout( function timer(){
console.log( i );
}, i*1000 );
}
The output generated by this code segment looked like the following:
ooo
ooo
ooo
ooo
ooo
6
6
6
6
6
I would greatly appreciate any help in clarifying the workings of this code. Thank you!