Jquery/JS scoping
<p>This may be pretty simple but it's stumping me. I'm trying to return a variable in javascript to another variable outside of the function's scope. For some reason, the assignment isn't occurring. Here's my code:</p>

<pre><code>var time = Math.round(((new Date()).getTime())/1000);

// first call to get data
var power_now = get_data(&lt;%= @user.id %&gt;, time);

function get_data(user_id, timestamp){
  var targetURL = "get/user_data?time_now="+timestamp+"&amp;user_id="+user_id;
  var power = 0;

  $.get(targetURL, function(data){
    power = data[0]['power'];
    alert(power);
  })

  return power;
}

$('body').html('&lt;h1&gt;'+power_now+','+power_then+'&lt;/h1&gt;')
</code></pre>

<p>If I place alert(power) within the .get function, the value is correct; however if I place it outside of the .get function, the value is 0.</p>

<p>Maybe I'm missing something about scoping in javascript?</p>

<p>Thanks!</p>
