JavaScript: Understanding let scope inside for loop [duplicate]
问题 This question already has answers here : Explanation of `let` and block scoping with for loops (3 answers) Closed last year . Please consider snippet below- for(let i = 1; i <= 5; i++) { setTimeout(function(){ console.log(i); },100); } In this case, logs inside setTimeout will contain values of variable i as per each iteration of the for loop, i.e the logs will be as follow 1 2 3 4 5 For this, I have read explanations over the Internet like - let creates a variable declaration for each loop