title: variable scoping in javascript
body: <p>My code is as follows:</p>
  
  <pre><code>jQuery(document).ready(function() {
          var pic = 0;
          FB.init({appId: '1355701231239404', status: true, cookie: true, xfbml: true});
          FB.getLoginStatus(function(response) {
          if (response.session) {
              pic = "http://graph.facebook.com/" + response.session.uid + "/picture";     
              alert(pic);
           } else {
              window.location = "index.php"
           }       
          });
  
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>The issue is that the pic inside my if statement has a different scope with the one I declared above? Why and how do I make them the same?</p>
  
  <p>What I want is to use this var pic (the one that has been assigned by the if statement) inside the body of my html. I will have another script inside the body, a document.write that uses this pic variable.. as of now when I do a document.write it always gives me 0, as if it's not assigned inside the if statement</p>