title: Return value from nested function in Javascript
body: <p>I have a function that is set up as  follows</p>
  
  <pre><code>function mainFunction() {
        function subFunction() {
              var str = "foo";
              return str;
        }
  }
  
  var test = mainFunction();
  alert(test);
  </code></pre>
  
  <p>To my logic, that alert should return 'foo', but instead it returns undefined. What am I doing wrong?</p>
  
  <p><strong>UPDATE</strong>: Here's my actual code (it's a function for reverse-geocoding with the Google API)</p>
  
  <pre><code>function reverseGeocode(latitude,longitude){
      var address = "";
      var country = "";
      var countrycode = "";
      var locality = "";
  
      var geocoder = new GClientGeocoder();
      var latlng = new GLatLng(latitude, longitude);
  
       return geocoder.getLocations(latlng, function(addresses) {
       address = addresses.Placemark[0].address;
       country = addresses.Placemark[0].AddressDetails.Country.CountryName;
       countrycode = addresses.Placemark[0].AddressDetails.Country.CountryNameCode;
       locality = addresses.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
       return country;
      });   
     }
  </code></pre>