title: Are there downsides to using var more than once on the same variable in JavaScript
body: <p>Before asking my question, let me give a disclaimer. I know what <code>var</code> does, I know about block scope, and I know about variable hoisting. I'm not looking for answers on those topics. </p>
  
  <p>I'm simply wondering if there is a functional, memory, or performance cost to using a variable declaration on the same variable more than once within a function.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>function foo() {
    var i = 0;
    while (i++ &lt; 10) {
      var j = i * i;
    }
  }
  </code></pre>
  
  <p>The previous could just have easily been written with the <code>j</code> variabled declared at the top:</p>
  
  <pre><code>function foo() {
    var i = 0, j;
    while (i++ &lt; 10) {
      j = i * i;
    }
  }
  </code></pre>
  
  <p>I'm wondering if there is any actual difference between these two methods. In other words, does the <code>var</code> keyword do anything other than establish scope?</p>
  
  <p>Reasons I've heard to prefer the second method:</p>
  
  <ol>
  <li>The first method gives the appearance of block scope when it's
  actually function scoped. </li>
  <li>Variable declarations are hoisted to
  the top of the scope, so that's where they should be defined.</li>
  </ol>
  
  <p>I consider these reasons to be good but primarily stylistic. Are there other reasons that have more to do with functionality, memory allocation, performance, etc.?</p>