Recall & Review
beginner
What is a stack overflow in programming?
A stack overflow happens when a program uses more memory on the call stack than is available. This usually occurs due to too many nested function calls or infinite recursion.
Click to reveal answer
beginner
How does recursion relate to stack overflow?
Recursion is when a function calls itself. If the recursion never stops or stops too late, it keeps adding calls to the stack, which can cause a stack overflow.
Click to reveal answer
beginner
What is the call stack in JavaScript?
The call stack is a place where JavaScript keeps track of function calls. Each time a function runs, it is added to the stack. When it finishes, it is removed.
Click to reveal answer
intermediate
What happens when a stack overflow occurs in JavaScript?
When a stack overflow happens, JavaScript throws a 'RangeError: Maximum call stack size exceeded' error and stops running the current execution context.
Click to reveal answer
intermediate
How can you prevent stack overflow caused by recursion?
You can prevent stack overflow by making sure recursive functions have a base case that stops the recursion, or by using loops instead of recursion.
Click to reveal answer
What causes a stack overflow in JavaScript?
✗ Incorrect
A stack overflow happens when the call stack exceeds its limit due to too many nested calls or infinite recursion.
What error message does JavaScript show when a stack overflow occurs?
✗ Incorrect
JavaScript throws a RangeError with the message 'Maximum call stack size exceeded' when a stack overflow happens.
Which of these can help avoid stack overflow in recursive functions?
✗ Incorrect
A base case stops recursion from continuing forever, preventing stack overflow.
What is the call stack used for in JavaScript?
✗ Incorrect
The call stack keeps track of which functions are running and in what order.
If a recursive function never reaches a base case, what will happen?
✗ Incorrect
Without a base case, recursion continues indefinitely, causing a stack overflow.
Explain what a stack overflow is and why it happens in JavaScript.
Think about how functions are added and removed from the call stack.
You got /4 concepts.
Describe how you can prevent stack overflow when writing recursive functions.
Focus on controlling when recursion ends.
You got /3 concepts.