title: Why does my javascript code skip a function asigned to a variable?
body: <p>I'm developing a web application based on google maps. When the user puts an address in the finder, the function prepareFinderQuery() is called. From this function, I call another one that should give me the coordinates of the given address. I'm trying to save the result in a variable but for some reason, the code is skipping the call to getCoordinatesFromAddress() until prepareFinderQuery() ends.</p>
  <pre><code>function prepareFinderQuery() {
  
        let address = $('#finder-input').val();
  
        let coords = getCoordinatesFromAddress(address);
  
        console.log(coords);
          
  }
  
  function getCoordinatesFromAddress(address) {
       
      for (let i = 0; i &lt; markers.length; i++) {
          markers[i].setMap(null);
      }
  
      markers = [];
      const geocoder = new google.maps.Geocoder();
  
      geocoder.geocode({ 
          address: address
      }, 
      (results, status) =&gt; {
          if (status == 'OK') {
              map.setCenter(results[0].geometry.location);
              map.setZoom(17);
  
              let marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location
              });
  
              markers.push(marker);
  
              let coords = JSON.stringify(results[0].geometry.location);
  
              console.log(coords);
  
              return coords;
          
            } else {
              alert('Address doesn't exists');
            }
      });    
  }
  
  </code></pre>
  <p>When I debug, I can see that when the program gets to
  <code>let coords = getCoordinatesFromAddress(address);</code> 'undefined' is assigned to coords. And then, the next line is executed, printing 'undefined' in the console. When the function ends, the program enters in getCoordinatesFromAddress() and then <code>console.log(coords);</code> prints the right coordinates. I don't have enough javascript experience and this is my first time using the Google Maps API, so I don't know if this is a usual javascript behaviour or maybe the Geocode object is launching some asynchronous process.</p>
  <p>Help please!</p>