Stuck in javascript variables closures
<p>I just wanted to assign position.coords.latitude and longitude to lat and lon vars but it seems that I am missing something because Console always says lat lon to be undefined.</p>

<pre><code>function init() 
{
    var lat;
    var lon;

    if (navigator.geolocation) {

       navigator.geolocation.getCurrentPosition(function(position)
       {
          lat = position.coords.latitude;
          lon = position.coords.longitude;     
       });
    }

    console.log(lat);
    console.log(lon);

}
</code></pre>
