CodingTrain / Intro-to-Data-APIs-JS

Working with Data and APIs in JavaScript
MIT License
754 stars 610 forks source link

Doubt regarding the program-flow in: Module 2 - exercise_04_array_button #58

Closed RobinKohrs closed 3 years ago

RobinKohrs commented 3 years ago

From the third to the fourth video some things changed in index.html. Basically it is the introduction of the POST request. What I do not understand is the flow of the JavaScript in exercise_04_array_button/public/index.html.

We are passing the data-object to the fetch-Post request in line 28. The two variables latand lon were first declared, however not initialized, in line 17. Then they were used to build the data-object in line 20 which is eventually passed into the fetch-function in line 28.

What I do not understand is how these two variables can hold the values of the geolocation. Because the geolocation we are obtaining only below in the lines 35-40. Probably this has to do with how the async and await logic works, but I just wanted to ask because it feels that I missed this piece😅

Incredible Video Series btw!!!