I need to perform some recursive operations using JavaScript.
Does JavaScript engine work like Java? For recursion Java starts a new stack on every recursive call. How does JavaScript handle this?
I need to perform some recursive operations using JavaScript.
Does JavaScript engine work like Java? For recursion Java starts a new stack on every recursive call. How does JavaScript handle this?
ECMAscript has no concept of tail optimization ... yet, if that was the question ?
What does tail optimization mean ?
It means that the stack frame is no longer necessary at the point of the recursive call, and therefore may be eliminated
That in turn means, since there is no official specification on that topic, its pretty much up to the interpreter how to handle this. Probably there are some optimizations going on under the hood (V8 ?), but better assume that a JS recursion gets not optimized at all.