Why can’t I pass the data from api as argument between functions like the above example code “showWeatherData (data)”? The problem will occur when the word “temperature min” in the blue or black area is clicked. Since the data will not changed accordingly.
e.g 1: “display1(data1.city, data1.list)” and “function display1(passdata, passdata2)”,
e.g 2: “display3(data1)” and “function display3(passdata3)”
But I have defined “passdata” and “passdata2” as “data1.city” and “data1.list” respectively. Both of them can be found as a callback function “display1(data1.city, data1.list)” in function getData().
That’s not how JS works. Those variables are defined inside the function, but you’re calling display1(passdata, passdata2) from the global scope which has no access to those variables.
One quick (but not very good) solution would be to move definition of those variables to the global scope (on the same level as const day = new Date();) and then reassign them in getData().
In the example code,
function getWeatherData () can pass data by using callback function “showWeatherData(data)” and “data” is apparently a parameter. Then, function showWeatherData (data) can obtain data.
I pored over this article before. And I would also like to know alternative solutions apart from that quick approach. Also, what makes function getWeatherData () call the showWeatherData(data) from the global scope successfully?