I'm writing a client for mpd (music player daemon) with node, using the node-mpdsocket library, but I appear to have run into a bit of confusion early on. In this example, response is an object, and response['state'] should return a string.
var togglePause = function() {
  var mpdState;
  mpd.send('status', function(response) {
    mpdState = response.state;
    // Here, console.log(mpdState) returns mpd's state correctly
    console.log(mpdState);
  });
  // Here, undefined is returned regardless of mpd's actual state
  console.log(mpdState);
}
I expected mpdState to return a string in both instances because both places where console.log are called are within the same function. However, this does not appear to be the case. 
 
    