I have a variable named w in my code, I have declared it globally and I am changing its value inside a function but when I print it outside the function it is undefined instead of showing its modified value, kindly help.
var w;
$http.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22islamabad%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")
.success(function (response) {
var result = response.query;
var temp=result.results.channel.item.condition.temp;
var text=result.results.channel.item.condition.text;
window.w = $scope.weather = temp+" "+text;
});
window.alert(w);