title: How to reason about an early return with a variable defined after
body: <p>I was looking through the code of a JS library and saw this pattern:</p>
  
  <pre><code>function module() {
      function func() {
          //...
          definedAfter();
          //...
      }
      return func;
      var x = "....";
      function definedAfter() {
          //...
          console.log(x); //outputs undefined
          //...
      }
  }
  </code></pre>
  
  <p>Google's Closure compiler flags the variable <code>x</code> as unused code, which seems reasonable, but the interesting part is that the variable is declared but with a value of <code>undefined</code> (due to hoisting).</p>
  
  <p>Is this a bug in the library? Or is there some subtle behavior that is being exploited here? Maybe some type of optimization? Do different browsers act differently with regard to this example?</p>
  
  <p>EDIT: I'm curious about the intent (bug or otherwise) of the original code, since it seems like <code>x</code> would always be <code>undefined</code>.</p>