title: JavaScript - saving variables inside functions without calling the functions
body: <p><strong>Can someone help me with a JavaScript riddle?</strong></p>
  
  <p>Consider the following JavaScript code:</p>
  
  <pre><code>var a[];
  
  for (i=0;i&lt;10;i++)
  {
      a[i] = function(){alert ("I am " + i);};
  }
  
  a[5]();
  </code></pre>
  
  <p>Now obviously, the last line will cause the alert to read "I am 9", and not "I am 5", since the value of <code>i</code> is 9 at the end of the <code>for</code> loop.</p>
  
  <p>I want the alert to print "what it is supposed to", but without changing the way which I call functions from the array, i.e. - no parameters.</p>
  
  <p>A hint I received: try defining a function which calls another function.</p>
  
  <p>Please help!!! Thank you :-)</p>