Difference between local variables and arguments
<pre><code>function addLinks () {
   for (var i=0, link; i&lt;5; i++) {
         link = document.createElement("a");
         link.innerHTML = "Link " + i;
         link.onclick = function (num) {
             return function () {
                 alert(num);
             };
         }(i);
}}
</code></pre>

<p>A closure is created for each link; each closure has reference to the scope in which it was created. Since argument <code>num</code> has been updated on each loop, on <code>click</code> on the first link it should alert <code>4</code>. Isn't it?</p>
