The For loop is triggering the setTimeout() function a total of 10 times.
To simplify, it can be demonstrated as follows...
setTimeout(function() { console.log(0); }, 0); # when i=0
setTimeout(function() { console.log(1); }, 100); # when i=1
setTimeout(function() { console.log(2); }, 200); # when i=2
setTimeout(function() { console.log(3); }, 300); # when i=3
and so forth...
Essentially, for each number between 0 to 9, the setTimeout
function schedules the console.log()
method to execute at intervals of 100 ms. Changing this value to 1000 will result in a one second delay between numbers being printed.
If you eliminate the multiplication of i by 100 and keep a constant interval (e.g., only 100), all the numbers will appear to be printed simultaneously after that fixed interval.