Home >Web Front-end >JS Tutorial >Analysis of the maximum number of recursive calls supported by JavaScript_javascript skills
Are you curious about how many recursive calls the JavaScript engine can make?
How many recursive calls
The following function will let you find the answer: (Inspired by Ben Alman's gist)
Three results:
What do these numbers represent? Mr. Aleph pointed out that in V8, the number of recursive calls depends on two quantities: the size of the stack and the size of the stack frame (the local variable that holds the parameters). You can verify this by adding a local variable in computeMaxCallStackSize() - it will return the low value.
Tail call optimization in ECMAScript 6
ES6 has tail call optimization: if the last step in a function is also a function call, it will be "skipped" instead of being called through a sub-function. This means that under ES6 (strict mode), you only need to change the computeMaxCallStackSize function slightly and it can execute forever.