Can someone please explain to me the following behaviour:
function getLatLong() { var geocoder = new google.maps.Geocoder(); var result = ""; geocoder.geocode ( { 'address': "London", 'region': 'uk' }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { result = results[0].geometry.location; alert('Im called second'); } else { alert("Geocode was not successful for the following reason: " + status); } }); alert('Im called first'); return result; } How is the second alert message being called before the first alert? I have an issue whereby I'm trying to return to value of the assigned variable 'result' but it keeps returned as an empty string even though it does get assigned a value from results[0].geometry.location. I have a horrible feeling I'm missing something very obvious here :/