I am trying to read a variable outside of a function. I am doing a country detection using an API and looking up a JSON feed. I get the result fine, but I want to be able to use this result outside of the function and I have tried my best, but can't understand how to fix this. My code attempt so far.
var country; // defining country outside of function.
jQuery.getJSON('https://api.wipmania.com/jsonp?callback=?', function (data) {
var country = data.address.country;
console.log(country) // this returns correct result
}); // end location country check function
console.log(country) // This is reading undefined as is not picking up the new var = country resulted from above function.
How do I use the new resulted country variable outside of the function?
Thank You