How to return value from an asynchronous callback function? [duplicate]

This is impossible as you cannot return from an asynchronous call inside a synchronous method. In this case you need to pass a callback to foo that will receive the return value function foo(address, fn){ geocoder.geocode( { ‘address’: address}, function(results, status) { fn(results[0].geometry.location); }); } foo(“address”, function(location){ alert(location); // this is where you get the … Read more

Is Chrome’s JavaScript console lazy about evaluating objects?

Thanks for the comment, tec. I was able to find an existing unconfirmed Webkit bug that explains this issue: https://bugs.webkit.org/show_bug.cgi?id=35801 (EDIT: now fixed!) There appears to be some debate regarding just how much of a bug it is and whether it’s fixable. It does seem like bad behavior to me. It was especially troubling to … Read more