I wonder how the event-loop works in javascript, I am using node.js but I guess that the same question apply to browsers.
I have some async call (let's say setTimeout
or $.ajax
or fs.readFile
)
and after a while the event-loop executes the callback
now when the callback
is getting executed, what happens behind the scene?
Does the it revive the stack that it used when it invoked the async stuff?
In practice what is the context/this that the callback is living in? and how does it work?
edit: thanks, I see.. just one more issue, how does the event loop "remembers" the scope of a callback?