Algorithms and Data Structures · Middle · Question 51 of 75

How can you avoid a stack overflow in deep recursion in JavaScript?

Explanation

JavaScript engines (except Safari) don't implement tail call optimization, so the call stack is limited to roughly ten thousand frames. An explicit array used as a stack lives on the heap and can grow much larger.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 51

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz