title: Please explain closures, or binding the loop counter to the function scope
body: <p>I've seen programmers assign events listeners inside loops, using the counter. I believe this is the syntax:</p>
  
  <pre><code>for(var i=0; i &lt; someArray.length; i++){
     someArray[i].onclick = (function(i){/* Some code using i */})(i);
  }
  </code></pre>
  
  <p>Could someone please explain the logic behind this, and this weird syntax, I've never seen this: </p>
  
  <pre><code>(function(i))(i);
  </code></pre>
  
  <p>Many thanks for your time and patience.</p>