Hi all,
I also figured out another way out to write the code for printing 1,2,3,4,5 in 1,2,3,4,5 seconds respectively without using let and only using var. this is regarding EP-11 | setTimeout + closures interview questions ( https://www.youtube.com/watch?v=eBTBG4nda2A&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=13 ). i have given the code below, kindly let me know if this could be considered as an another solution since it was giving me the correct output.
function altSol(){ for (var i = 1;i<=5; i++){ setTimeout(function (i){ console.log(i); }(i),i*1000); } } altSol();
2 Comments
Magnificent web site. Plenty of useful info here. I’m sending it to a few friends ans also sharing in delicious. And of course, thanks for your sweat!
You should take part in a contest for one of the best blogs on the web. I will recommend this site!