Call Stack
Call Stack
Interviewquestion-153
Follow on
@Duvvuru Kishore
The call stack is a mechanism that JavaScript
uses to keep track of function calls.
When a function is called, JavaScript adds it to the top of
the call stack.If that function calls another function, the
new function is also added to the top of the stack.This
process continues, stacking each new function on top of
the previous ones.
f2
f1
Once a function finishes executing, it is removed (or
"popped") from the top of the stack, and the program
returns to the function below it. This process continues
until the stack is empty, meaning all the functions have
finished executing.
f2
f1 f1 f1
call stack helps JavaScript keep track of where it is in
a program, ensuring that function calls are executed
in the correct order. It's a "last in, first out" (LIFO)
structure, meaning the last function added to the
stack is the first one to be executed and removed.