How to pass variable to anonymous function
<p>I want to pass variable <code>setTimeout</code>function and do something with that. When I alert value of <code>i</code> it shows me numbers that i did not expected. What i m doing wrong? I want log values from 1 till 8.</p>

<pre><code>var end=8;
for (var i = 1; i &lt; end; i ++) {
       setTimeout(function (i) {
           console.log(i);   

       }, 800);
   }
</code></pre>
