title: how to return value to parent function from nested anonymous function
body: <p>I have a javascript function which should return a geocoding for a string:</p>
  
  <pre><code>    function codeAddress(address) {
      var result = (new google.maps.Geocoder()).geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          return String(results[0].geometry.location.Ya)+','+String(results[0].geometry.location.Za)
        } else {
          return status;
        }
      });
      console.log(result);
      return result
  }
  </code></pre>
  
  <p>However it returns "undefined". I understand the bug here,i.e, since javascript is asynchronous, its returning from the function <code>codeAddress</code> even before <code>function(results, status)</code> gets fully executed. But I need to know whats the solution here and the best practice.</p>