I can not figure this out…
I want to:
declare a variable, run a function that changes the value of that variable and then then alert the value of the new value.
Like so:
function loadApp(){
FB.api('/me', function(response) {
var posLat;
getLocation();
console.log(posLat);
});
}
function getLocation(){
posLat = "hey";
}
The alert should display 4 but just alerts undefined. Am i bein stupid?
posLatis defined inside a function, therefore making it a local function that cannot be used outside of its surround scope. That’s whygetLocationcan’t modify it. In fact, it’s creating a global variable calledposLaton the window object. As the comments on my post suggest, setposLatto the return value ofgetLocation: