How do Execution Context interact with Asynchronous Execution?
For a while now, I have been trying to wrap my head around the execution context. Originally I didn't think it was going to be such a rabbit hole. My question is how is an execution context that was created from a async function referencing the function that called it? is it just direct referencing the function? If so, what is happening when the referenced function finishes execution? Is it just a dangling reference at that point or is it more so a closure situation?
I also didn't know if I should tag this question as noob or deep question, because I know they work when async isn't involved and I even know how they work with the eval function and in Web Workers.
Solution:Jump to solution
It's more of a closure situation. They call it lexical scoping or lexical environment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
MDN Web Docs
Closures - JavaScript | MDN
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives a function access to its outer scope. In JavaScript, closures are created every time a function is created, at function creation time.
3 Replies
Solution
It's more of a closure situation. They call it lexical scoping or lexical environment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
MDN Web Docs
Closures - JavaScript | MDN
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives a function access to its outer scope. In JavaScript, closures are created every time a function is created, at function creation time.
i think there's no difference for async because event loop and such
Oh! That is good to know! Thank you! The only difference is that they are in different queue on the event loop one being on the task queue the other on the micro task queue. Which was why I was so confused