title: JavaScript Hoisting in Repl.it
body: <p>I put this code into repl.it expecting to get an undefined is not a function error.</p>
  
  <pre><code>foo();
  
  var foo = function (){
      console.log("Hey foo");
  };
  </code></pre>
  
  <p>Due to hoisting, I thought it would be interpreted as</p>
  
  <pre><code>var foo;
  foo();
  
  foo = function (){
      console.log("Hey foo");
  };
  </code></pre>
  
  <p>Instead it logged "Hey foo" to the interactive interpreter. </p>
  
  <p>Does hoisting only apply within the scope of a function or what's happening here?</p>
  
  <p>When I wrapped the above code in a function, as below, the results were as expected, indeed <code>undefined is not a function</code>.</p>
  
  <pre><code>function fooTester = (){
      foo();
      var foo = function (){
          console.log("Hey foo");
      }
  }
  fooTester();
  </code></pre>
  
  <p>Just looking for some clarification on what's going on here. <img src="https://i.stack.imgur.com/hYOoF.png" alt="repl.it image"></p>