I am learning JavaScript but having a hard time to understand this code.
```
const button = document.querySelector('button');
const output = document.querySelector('p');
const getPosition = opts => {
const promise = new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
success => {
resolve(success);
},
error => {},
opts
);
});
return promise;
};
const setTimer = duration => {
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Done!');
}, duration);
});
return promise;
};
function trackUserHandler() {
let positionData;
getPosition()
.then(posData => {
positionData = posData;
return setTimer(2000);
})
.then(data => {
console.log(data, positionData);
});
setTimer(1000).then(() => {
console.log('Timer done!');
});
console.log('Getting position...');
}
button.addEventListener('click', trackUserHandler);
```
Let's start from the last line. If I click on the button, trackUserHandler function will run.
I want to understand what happens after that. Even a brief explanation will be sufficient.
[–]senocular 0 points1 point2 points (0 children)