I’m having an issue assigning a variable declared in an outer function inside a nested function. I think it might be an async or hoisting issue but I can’t figure it out. I did some testing and that is working like I’d expect and I can’t see where the difference is between my working test and my not working app.
You can see in this pen that the variable level is declared in the outer most function first() and logged from that function, but it’s overridden by the innermost function third() and the log correctly displays “third”.
However in my weather app the msg variable isn’t being assigned the same way even though the nesting appears to be identical. The only difference I can discern has to do with the async API call, which may be way the console.log shows the unchanged version.
Any help explaining what’s going on and how I can test/view the difference better myself is tremendously appreciated.