The following jQuery code attempts to store a client's IP address in a global variable during the callback for an ajax GET request.
Code
  var userip = null;
  $.ajax({
    url: "http://ipinfo.io",
    type: 'get',
    dataType: 'jsonp',
    async: false,
    success: function(data) {
      userip = data.ip;
      console.log(userip); // prints unique ip address
    }
  }).done(console.log(userip)); // prints null
Knowing that GET requests are usually executed asynchronously (but requiring otherwise), I have marked async: false in the JSON spec. For added measure, I call done() to ensure the request has finished before continuing.
Nevertheless, printing userip returns null after the GET request but prints the unique client IP during the ajax success callback. 
Any explanation would be greatly appreciated. Thanks in advance.

async: false,. Instead, look into using the callback correctly or using deferred / returning a promise