I am teaching myself javascript and one of the exercises I have tried makes no sense to me.
In the code below 'position' is a parameter that must be defined. However, when I pass the function, displayLocation
as an argument to navigator.geolocation.getCurrentPosition
, the code executes flawlessly, despite no argument being passed. When I try coords.longitude
in the console without the position
argument, it does not work.
How does the code work without a defined argument?
function displayLocation(position)
{
var latitude = latitude.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("location");
div.innerHTML = latitude + " " + longitude;
}
navigator.geolocation.getCurrentPosition(displayLocation);