retrun values outside JS function

i have A map js function which let me to get the latitude and longitude from map,
however , I want to get those data outside the function in other variables to used again.

How Can I do It

map.on('click', function (e) {
    lat=e.latlng.lat;
    
          lon =  e.latlng.lng;
          
          document.getElementById('latitude').textContent = lat;
         document.getElementById('longitude').textContent = lon;

});
// console.log( lat,lat);

when I console ( lat,lat) it display to me that they are undefined