title: Understanding variable capture by closures in Javascript/Node
body: <p>Is there a definite source on variable capture in Javascript besides the standard (it's a pain to read the standard)?</p>
  
  <p>In the following code <code>i</code> is copied by value:</p>
  
  <pre><code>for (var i = 0; i &lt; 10; i++)
  {
      (function (i)
      {
          process.nextTick(function ()
          {
              console.log(i)
          })
      }) (i)
  }
  </code></pre>
  
  <p>So it prints 1..10. <code>process.nextTick</code> is an analog of <code>setTimeout(f,0)</code> in node.</p>
  
  <p>But in the next code i doesn't seem to be copied:</p>
  
  <pre><code>for (var i = 0; i &lt; 10; i++)
  {
          var j = i
          process.nextTick(function ()
          {
              console.log(j)
          })
  }
  </code></pre>
  
  <p>It prints 9 10 times. Why? I'm more interested in a reference/general article than in explaining this concrete case of capture.</p>