Closure confusion
<p>I am having some confusion regarding this Closure thing. I have two separate codes below that look similar but their output are different. </p>

<pre><code>function setup(x) {
var array = [];
for(var i=0;i&lt;arguments.length;i++){
    array[i]= arguments[i];
}
return array;
}
console.log(setup('a','b'));  // will output ["a","b"] 

--------------
function f() {
var i, array = [];
for(i = 0; i &lt; 3; i++) {
    array[i] = function(){
        return i;
    }
}
return array;
}

var a = f();                 
console.log(a());       //output: [function(),function(),function()]
console.log(a[0]());    //output: 3 //same output in a[1]() and a[2]() calls as well
</code></pre>

<p>Now my question is, how come the output is different? both of the codes above return an array. in the first code, it prints all elements in array correctly whereas in the second code, why doesn't it print [1,2,3]??? </p>
