title: Javascript can't access global variables outside function
body: <p>I'm using google map geocoding to  get latitude,longitude value from address.Here is my code,</p>
  
  <pre><code>var latd;
  var lond;
  geocoder.geocode({ 'address': address }, function (results, status) {
  
      if (status == google.maps.GeocoderStatus.OK) {
         console.log(place);
         var latd = results[0].geometry.location.lat();
         var lond = results[0].geometry.location.lng();
       }
      console.log(latd);
  });
  //console.log(latd);
  </code></pre>
  
  <p>When access the variable <code>latd</code> outside function, its value seems <code>undefined</code>. What's the issue with the above code?</p>
  
  <p>Update1:</p>
  
  <pre><code>    getlatlang(address);
      console.log(latd);//Not defined
  
  
  function getlatlang(address)
  {
      var geocoder = new google.maps.Geocoder();
      geocoder.geocode({ 'address': address }, function (results, status) {
  
          if (status == google.maps.GeocoderStatus.OK) {
              //console.log(place);
              latd = results[0].geometry.location.lat();
              lond = results[0].geometry.location.lng();
               return latd,lond;
               }
  
       });
  }
  </code></pre>