(function timer() {
for (var i = 0; i <= 5; i++) {
(function () {
setTimeout(function clog() {
console.log(i);
}, i * 1000);
})();
}
})();
This is the output-
6
6
6
6
6
6
how is the IIFs getting loaded on the stack? are all of them pushed and then processed and popped one by one to get the i = 6? And the output does wait for 1 sec while printing 6.