What is call stack
A call stack is a mechanism for an interpreter to keep checking which function should be called
- When a script calls a function, the interpreter adds it to the call stack and then starts carrying out the function.
- Any functions that are called by that function are added to the call stack further up, and run where their calls are reached.
- When the current function is finished, the interpreter takes it off the stack and resumes execution where it left off in the last code listing.
- If the stack takes up more space than it was assigned, a "stack overflow" error is thrown.
https://developer.mozilla.org/en-US/docs/Glossary/Call_stack
What is the event loop
A event loop is a mechanism that deals with the coordination between “task queue” and “call stack”.
What is a task queue?
Task queues is a list of messages that wait to be processed in call stack. In the other word, they are asynchronous from call stack. Each message is associated with a function, which get called to handle the message. There are two different task queues:
- micro-task queue: This queue has higher priority and includes microtasks such as Promise.
- task queue: The event loop will process all tasks in the MicroTask Queue before it gets to the TaskQueue. It includes setTimeout, setInterval…
https://2014.jsconf.eu/speakers/philip-roberts-what-the-heck-is-the-event-loop-anyway.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Event_loop
http://latentflip.com/loupe/