Event Loop in JS
Event loop
There are several internals inside javascript event loop:
- The call stack
- The Event Loop
- Macrotasks (Task Queue)
- Microtasks (Microtask Queue)
Call stack
The call stack is where JS tracks what function is currently executing. It is working as a stack way (Last in First out).
function greet() {
console.log("Hello, world!");
}
function main() {
greet();
}
main();
what javascript do is to push the functions into the stack and then execute them in order. And because javascript is a single-threaded language, only one thing is on the top of the stack at a time.
- push main();
- push greet();
- push console.log
reference
- https://javascript.info/event-loop