Recall & Review
beginner
What is the call stack in JavaScript?
The call stack is a list that keeps track of all the functions that are currently running. It works like a stack of plates: the last function added is the first one to finish.
Click to reveal answer
beginner
What happens when a function is called in JavaScript?
When a function is called, it is added (pushed) to the top of the call stack. The program runs the function, and when it finishes, the function is removed (popped) from the stack.
Click to reveal answer
intermediate
What is a stack overflow error?
A stack overflow happens when too many functions are added to the call stack without finishing, usually because of infinite recursion. The stack runs out of space and the program crashes.
Click to reveal answer
intermediate
How does the call stack handle nested function calls?
When a function calls another function, the new function is added on top of the stack. The program finishes the new function first, then returns to the previous one.
Click to reveal answer
intermediate
Explain the order of execution using the call stack with this code:<br><pre>function a() { b(); } function b() { c(); } function c() { console.log('Done'); } a();</pre>The call stack adds 'a' first, then 'b' when 'a' calls it, then 'c' when 'b' calls it. 'c' runs and logs 'Done', then 'c' is removed, then 'b' finishes and is removed, then 'a' finishes and is removed.
Click to reveal answer
What does the call stack do when a function finishes running?
✗ Incorrect
When a function finishes, it is removed (popped) from the top of the call stack.
What causes a stack overflow error in JavaScript?
✗ Incorrect
A stack overflow happens when the call stack gets too big, usually from infinite recursion.
If function A calls function B, what happens to the call stack?
✗ Incorrect
Function B is added on top of the stack, so it runs first before returning to function A.
Which function runs first in this code?<br>
function x() { y(); } function y() { console.log('Hi'); } x();✗ Incorrect
Function x runs first, then it calls y, which runs next.
What data structure best describes the call stack?
✗ Incorrect
The call stack works like a stack: the last function added is the first to finish.
Describe how the call stack manages function calls and returns in JavaScript.
Think about how plates stack and unstack.
You got /4 concepts.
Explain what happens when a stack overflow error occurs and why it happens.
Imagine stacking plates endlessly without removing any.
You got /4 concepts.