DEV Community

Discussion on: An interesting Javascript interview question

Collapse
 
miteshkamat27 profile image
Mitesh Kamat

You can also go for the IIFE solution:
for(var i=0; i<5; i++){
(function(i){
setTimeout(() => {
console.log(i)
},0)
})(i)
}

Collapse
 
danimal92 profile image
Daniel Zaltsman

Nice one!