title: javascript setInterval() and Variable Scope
body: <p>OK, I have read several questions here with the same title but still couldn't find a solution to my problem. I'm working on a basic javascript count down timer and I'm stuck on updating the value of the <code>a</code> variable.</p>
  
  <pre><code>a = 100;
  var i = setInterval( function(){ timer( a ); }, 1000 );
  
  function timer( a ){
      console.log( a );
      if( a &lt; 1 ){     
          console.log( 'Reaching Stop' ); 
              clearInterval( i );
              return;         
      } 
      a -= 1;
  }
  </code></pre>
  
  <p>As I'm decrementing the value of <code>a</code> by -1, <code>console.log( a )</code> should be 1 less every time i.e</p>
  
  <pre><code>100 99 98 ......
  </code></pre>
  
  <p>But <code>console.log( a )</code> is always giving <code>100</code></p>
  
  <p>newbie to javascript here please be gentle.
  thanks.</p>