title: How to extract correctly local variables from Javascript function?
body: <p>Actually i have this code :</p>
  
  <pre><code>var options = {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 0
  };
  
  function success(pos) {
    var crd = pos.coords;
  
    var lat = crd.latitude;
    var lon = crd.longitude;
    var acc = crd.accuracy;
    console.log("latitude is ", lat);
  
    var mydata = {latitude:lat, longitude:lon, accuracy:acc};
    return mydata;
  };
  
  function error(err) {
    console.warn('ERROR(' + err.code + '): ' + err.message);
  };
  
  navigator.geolocation.getCurrentPosition(success, error, options);
  </code></pre>
  
  <p>I have a lot of doubts about the scope management. How can i get the variables lat, lon and acc out of the function? with return doesn't work... I know that if i declare the variable without the var this will work but I've read that it is a bad practice. I want to extract those three variables for use it with another application like OpenStreetMap...  or OpenWeather.</p>
  
  <p>Thanks a lot.</p>