Call Stack Flashcards

1
Q

What is the call stack and how does it work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens when the call stack overflows?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can the call stack be manipulated directly?

A

No!

The call stack is managed automatically by the JavaScript engine, and cannot be directly manipulated by code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is event loop? What is the difference between call stack and task queue?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly