title: Best way to 'return true' based on conditions from nested functions
body: <p>This may be a novice question but I am trying to create a function that <strong>returns true</strong>. However, this is based on what happens within several other functions inside.</p>
  
  <pre><code>function checkGeo(){
  
      // CHECK FOR GEOLOCATION
      if( "geolocation" in navigator ) {
  
          navigator.geolocation.getCurrentPosition( function(position){
              sessionStorage.pinlat = position.coords.latitude; 
              sessionStorage.pinlon = position.coords.longitude; 
              // position object is set!
          });
  
          // position is not defined
          if ( position.coords.latitude &amp;&amp; position.coords.longitude ){ 
             return true; 
          }
  
      }
  
  }
  </code></pre>
  
  <p>This is the order I want things to happen with my geolocation check but I'm a bit surprised that the nested if is tested before the getCurrentPosition method finishes. </p>
  
  <p>Putting this condition within the getCurrentPosition success function and returning true from there does not make checkGeo return true. How do I check if this asyncronous function has ended and therefore check its results in order to <code>return true</code>?</p>