title: Can someone help explain how a setTimeout within a for loop works? Does this have anything to do with closure
body: <pre><code>var result = 0;
  
  for (var i=0; i &lt; 3; i++) {
    setTimeout(function() {
      result += i;
    }, 1000);
  }
  </code></pre>
  <p>Why will result equal 9 and not 3 at the end of this?</p>