title: jQuery variable becomes undefined for no reason
body: <p>I have the following code, in which I want to save the content of the file <code>bar.txt</code> in the variable <code>foo</code>:</p>
  
  <pre><code>var foo;
  
  jQuery.get('http://example.com/bar.txt', function(data) {
       foo = data;
       alert(foo);
  });        
  
  alert(foo);
  </code></pre>
  
  <p>The problem is that apparently, after the jQuery function ends the variable becomes undefined (even though it was declared <strong>outside</strong> that scope). The first <code>alert(foo)</code> displays the content of the file properly, but the second one displays nothing.</p>
  
  <p>Can anybody tell me what is happening here?</p>