title: How each call finds the variable outside a for loop which includes a inner function?
body: <p>Regarding the <em>let Declarations in loops</em> in book <a href="https://rads.stackoverflow.com/amzn/click/com/1593277571" rel="nofollow noreferrer" rel="nofollow noreferrer">Definitive JavaScript Developer guideline</a>, the code: </p>
  
  <pre><code>var funcs = [];
  
  for (let i = 0; i &lt; 10; i++) {
      funcs.push(function() {
          console.log(i);
     });
  }
  
  funcs.forEach(function(func) {
      func();  // outputs 0, then 1, then 2, up to 9
  })
  </code></pre>
  
  <p>It says:</p>
  
  <blockquote>
    <p>The let declaration creates a new variable i each time through the loop, so each function created inside the loop gets its own copy of it. Each copy of i has the value it was assigned at the beginning of the loop iterations in which it was created..</p>
  </blockquote>
  
  <p>I want to know, when invoke the function <code>func()</code>, how and where it finds the <code>i</code> value for each element in array of <code>funcs</code>. All element in <code>funcs</code> are same </p>
  
  <pre><code>ƒ () {
      console.log(i);
    }
  </code></pre>
  
  <p>Could someone illustrate how each step happens when call the function in the above code? (I sort of understand that, if use <code>var</code> instead of <code>let</code>, the global variable <code>i</code> is what each call finds.)</p>