title: Javascript - scope of nested for loop index
body: <p>I remember variables are function scoped in Javascript. But, how is the behavior if I redefine the local variable in a loop. One common use case is nested loops.
   In the below code, if I change j to i, the outer for loop terminates after one iteration as the value of i in outer scope is same as inner for loop. Since I use var, I was expecting (similar to other language) it is redefined inside inner fo loop. Does this mean in JS, there is no way to redeclare and use local variable within function scope.</p>
  
  <pre><code>for (var i = 0, len = x.length; i &lt; len; i++) {
              ...
              for (var j = 0, len = y.length; j &lt; len; j++) {
                  ...
              }
          }
  </code></pre>