I am reading through the following article: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-22-async-javascript-and-http-requests/modules/wdcp-22-basics-of-asynchronous-javascript/articles/javascript-concurrency-model-and-event-loop
In this section:
-
console.log("This is the first line of code in app.js.");
is added to the stack, executes, then pops off of the stack. -
setTimeout()
is added to the stack. -
setTimeout()
’s callback is passed to be executed by a web API. The timer will run for 3 seconds. After seconds elapse, the callback function,usingsetTimeout()
is pushed to the Event Queue. - The Event Loop, meanwhile, will check periodically if the stack is cleared to handle any messages in the Event Queue.
-
console.log("This is the last line of code in app.js.");
is added to the stack, executes, then pops off of the stack. - The stack is now empty, so the event loop pushes
usingsetTimeout
onto the stack. -
console.log("I'm going to be queued in the Event Loop.");
is added to the stack, executes, gets popped -
usesetTimeout
pops off of the stack.
When is setTimeout()
popped from the stack?