Call Stack Flashcards
What is the call stack and how does it work?
It’s data structure that stores information about the active function calls in a program.
It operates on a “Last In, First Out” (LIFO) basis:
When a function is called, it is added to the top of the stack, and when it returns, it is removed from the top.
By examining the call stack, we can trace the order in which functions are called and identify the source of errors or unexpected behavior in our code.
What happens when the call stack overflows?
When the call stack becomes too large, it can cause a stack overflow error, which occurs when the stack runs out of space and is unable to add any more function calls.
Can the call stack be manipulated directly?
No!
The call stack is managed automatically by the JavaScript engine, and cannot be directly manipulated by code.
What is event loop? What is the difference between call stack and task queue?
The event loop is a single-threaded loop that monitors the call stack and checks if there is any work to be done in the task queue. If the call stack is empty and there are callback functions in the task queue, a function is dequeued and pushed onto the call stack to be executed.