title: JavaScript: variable assignemnt in for statement | precede or inside
body: <p>I have seen both....variable declaration in or before the for statement.  Which is better?  Here is an example snippet.</p>
  
  <pre><code>MC.initAll = function() {
      var iterate = [MC, Su], 
          l = iterate.length, 
          i, 
          key;
      for( i = 0; i &lt; l; i++ ) {
          for( key in iterate[i]) {
              if( iterate[i].hasOwnProperty(key) &amp;&amp; iterate[i][key].hasOwnProperty("init") ) {
                  iterate[i][key].init();
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Pros of putting at top of function outside the for statement:</strong></p>
  
  <ul>
  <li>less code due to using the same var statement</li>
  <li>already hoisted , js does not have to</li>
  <li>internal working made more explicit</li>
  <li>will pass jshint.com</li>
  </ul>
  
  <p><strong>Pros of putting in the for statement</strong></p>
  
  <ul>
  <li>easy visual inspect to verify declaration took place in function</li>
  </ul>