1
function factorialNormal(n) {
  if (n === 1) {
    return n
  }
  return n + factorialNormal(n - 1)
}
function factorialWithTail(n, acc) {
  if (n === 1) return acc;
  return factorialWithTail(n-1, n + acc)
}

recursion function is fast than tail-recursion and the tail use more memory, causing the maximum call stack

enter image description here

Detailed answer here: ES6 Tail Recursion Optimisation Stack Overflow

1
  • 1
    AFAIK, v8 does not have tail recursion optimization Commented Jul 12, 2022 at 9:30

1 Answer 1

3

There is no TCO on V8 currently.

Here is the tracking ticket for this feature.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.