title: Scope of uninitialized variable in JavaScript
body: <p>I cannot understand why this code is behaving as it is:</p>
  
  <pre><code>for (var i = 1; i &lt; 3; i++) {
      var j;
      if (!j) {
          j = 1;
      } else {
          alert("why are we here? j shouldn't be defined but it's " + j);
      }
  }
  </code></pre>
  
  <p>(<a href="http://jsfiddle.net/ec3jwz6n/3/" rel="noreferrer">jsFiddle</a>)</p>
  
  <p>If I set <code>j</code> to <code>null</code> and check for <code>null</code>, it works the way I think it should.</p>
  
  <p>This isn't how Java, C#, C++, etc. work, hence, the confusion.</p>