title: Facebook API, Javascript SDK & variable scope
body: <p>I've got a problem of variable scope with this code:</p>
  
  <pre><code>var likesString = "";
  
  var getLikes = function() {
    friend_ids = ["me", "123456789", "0987654321"];
    likesString = "";
  
    var likesArray = new Array();
    var i = 0;
    for (i = 0; i &lt; friend_ids.length; i++) {
      FB.api('/'+ friend_ids[i] +'/likes', function(response) {
        var tmpLikesString = "";
        if (response.data) {
          likes = response.data;
          var j = 0;
          for (j = 0; j &lt; likes.length; j++) {
            if (likes[j]["category"] == "Movie") {
              tmpLikesString = likes[j]["id"];
            }
          }
        } else {
          console.log("Error looking for likes");
        }
        likesArray.push(tmpLikesString);
        console.log('In FB.api:'+  likesArray);
      });
      console.log('Out FB.api:'+  likesArray);
    }
    likesString = likesArray.join(',');
    console.log("likes : " + likesString);
   };
  </code></pre>
  
  <p>Inside FB.api, my var "likesArray" works, but when I'm out of it, it's like nothing happen to it…</p>
  
  <p>The output if it can help to understand:</p>
  
  <pre><code>In FB.api:
  In FB.api:,
  In FB.api:,,
  In FB.api:,,,208509052512525
  In FB.api:,,,208509052512525,
  In FB.api:,,,208509052512525,,153960391321494
  (3)Out FB.api:
  likes : 
  </code></pre>
  
  <p>Thank you.</p>