Question from the Javascript test

What is the difference between the two loops?

Expert

Consider these two loops:

for (var i = 0; i < 3; i++) {
  setTimeout(()=> console.log(i), 1);
}

for (let i = 0; i < 3; i++) {
  setTimeout(()=> console.log(i), 1);
}

What are the expected outputs?

Author: Clément DevosStatus: PublishedQuestion passed 252 times
Edit
2
Community Evaluations
developer avatar
Ronan
29/01/2024
Approche très subtile, mais très judicieuse pour vérifier les connaissances sur la portée et les concepts de Queue/Stack en JS !