title: Is it bad practice to use the same variable name in multiple for-loops?
body: <p>I was just linting some JavaScript code using JSHint. In the code I have two for-loops both used like this: </p>
  
  <pre><code>for (var i = 0; i &lt; somevalue; i++) { ... }
  </code></pre>
  
  <p>So both for-loops use the var i for iteration.</p>
  
  <p>Now JSHint shows me an error for the second for-loop: "'i' is already defined". I can't say that this isn't true (because it obviously is) but I always thought this wouldn't matter as the var i is only used in that specific place. </p>
  
  <p>Is it bad practice to use for-loops this way? Should I use a different variable for each for-loop in my code like</p>
  
  <pre><code>//for-loop 1
  for (var i = 0; ...; i++) { ... }
  
  //for-loop 2
  for (var j = 0; ...; j++) { ... }
  </code></pre>
  
  <p>Or is this on e of the errors I can ignore (because it doesn't break my code, it still does what it is supposed to do)?</p>
  
  <p>JSLint btw. stops validating at the first for loop because I don't define var i at the top of the function (that's why I switched to JSHint in the first place). So according to the example in this question: <a href="https://stackoverflow.com/questions/6803305/should-i-use-jslint-or-jshint-javascript-validation/10763615#10763615">Should I use JSLint or JSHint JavaScript validation?</a> – I should use for-loops like this anyway to confirm JSLint: </p>
  
  <pre><code>...
  var i;
  ...
  //for-loop 1
  for (i = 0; ...; i++) { ... }
  ...
  //for-loop 2
  for (i = 0; ...; i++) { ... }
  </code></pre>
  
  <p>This also looks good to me, because this way I should avoid both errors in JSLint and JSHint. But what I am uncertain about is if I should use a different variable for each for-loop like this: </p>
  
  <pre><code>...
  var i, j;
  ...
  //for-loop 1
  for (i = 0; ...; i++) { ... }
  //for-loop 2
  for (j = 0; ...; j++) { ... }
  </code></pre>
  
  <p>So is there a best practice for this or could I just go with any of the codes above, meaning I choose "my" best practice?</p>