What is Tail Call Optimization (TCO) and under what conditions does the ECMAScript specification mandate it?

JavaScript Professional Hard

JavaScript Professional — Hard

What is Tail Call Optimization (TCO) and under what conditions does the ECMAScript specification mandate it?

Key points

  • TCO reuses stack frames to prevent stack overflow in deep recursion.
  • ECMAScript mandates TCO in strict mode when the return value is directly from a call expression.
  • TCO does not convert recursive functions to iterative loops or apply only to async functions.

Ready to go further?

Related questions