for (let i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, i * 1000);
}
In the above mentioned code, we are getting 0,1,2,3,4 as output with the time period of 1 seconds. As we are giving time interval as i*1000, then why time interval is not increasing. I mean inside the loop when i value is 3 or 4 time interval would be 3 seconds or 4 seconds. It should keep on increasing as it depends on i. I am having small idea about event loop and callback queue. But I couldn't able to relate it here. Please explain.
setTimeout()doesn't halt the execution of the loop.