title: Returning variables inside JS / JSON functions
body: <p>I'm trying to understand JSON, callbacks, etc within JS.  From the altered example below, you'll see that I'm in a function callback from $.getJSON.  Then, I jump into getSomething() and expect it to alter my result variable.  It alters it within the scope of the function, but not when I jump out of that function.  </p>
  
  <p>You'll see from the 2 console.log()'s that the first one displays correct, and the second one doesn't.  I'm sure the answer to my question has to do with returning variables via. callback, but could someone enlighten <br>me :)</p>
  
  <p>Thanks!</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>$.getJSON('/cart.js', function (cart, textStatus) {
    var result = '';
    result += 'Sample Stuff';
    StackOverflow.getSomething(param1, param2, function(a, b) {
      for(j=0; j &lt; b.length; j++) {
        if (b.options[j] != 'Default Title') {
          if (a.options[j].name.indexOf("Color") &gt; -1) {
            result += b.options[j].name;
            console.log(result); // &lt;-- It comes out correct (Sample Stuff + b.options...)
          }
        }
      }
    });
    console.log(result); // &lt;-- It comes out incorrect, just (Sample Stuff)
  });
  </code></pre>