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 264 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!