Here is my code:
lat = position.coords.latitude;
navigator.geolocation.getCurrentPosition is an async function, it's only going to call the function and thus run the "inside" code once it has retrieved the position. This is why you first see the "outside" message (at which point
lat is indeed undefined) and then the inside message.
If you need to access the value of
lat, you'll need to wait till it's defined, for example by calling another function from inside the