title: how come function doesn't wait for another function
body: <p>I have 2 functions, function A calls function B which geocodes an address and returns the LatLng object back to function A but somehow, function A doesn't wait for function B to return result from Google. </p>
  
  <pre><code>function A() {
      var address = document.getElementById("txtbox").value;
      //geocoding here
      var here = B(address);
      if (here == null) {
          console.log("seems like geocode didn't work, defaulting value");
  </code></pre>
  
  <p>and in function B</p>
  
  <pre><code>function B(address) {
      var here;
      geocoder = new google.maps.Geocoder();
      geocoder.geocode( { 'address': address}, function(results, status) {
          console.log("geocoding");                                               
          if (status == google.maps.GeocoderStatus.OK) {
              console.log(results[0].geometry.location);
              currentlatlng = results[0].geometry.location;
              lng = currentlatlng.lng();
              lat = currentlatlng.lat();
              here = new google.maps.LatLng(lat, lng);
          } else {
              console.log("Geocode was not successful for the following reason: " + status);
          }
      });
  
      return here;
  }
  </code></pre>
  
  <p>but seems like the output for the console is </p>
  
  <pre><code>seems like geocode didn't work, defaulting value
  geocoding
  </code></pre>
  
  <p>hence, it seems like function A calls function B and then proceeds it..</p>
  
  <p>i thought it would wait but then again as per my understanding of how google maps api work, it doesn't 'wait' per se, so what should i do?</p>