var newIp;
function getIP(json) {
document.write("My public IP address is: " + json.ip); //<-- This works properly
var newIp = json.ip; //<-- Trying to change newIp into a global variable.
console.log(typeof json.ip); //<-- Returns "string"
}
console.log(newIp); //<-- outputs to undefined?? Why??
There is also a script that I included to the index.html "src="http://api.ipify.org?format=jsonp&callback=getIP" and I do get the local IP address "json.ip" to work properly.
I cannot figure out how to turn the "json.ip" into a global variable to use in other parts of my app. Can someone give me a real example of how to do this?