Are any JavaScript engines tail call (TCO) optimized?

clofresh picture clofresh · Sep 7, 2010 · Viewed 25.6k times · Source

I have a tail recursive pathfinding algorithm that I've implemented in JavaScript and would like to know if any (all?) browsers would possibly get stack overflow exceptions.

Answer

Tim Sylvester picture Tim Sylvester · Sep 7, 2010

The ECMAScript 4 specification was originally going to add support for TCO, but it was dropped:

No more tail calls in JavaScript?

As far as I know, no widely-available implementations of JavaScript currently do automatic TCO. This may be of use to you, though:

Tail Call Optimization

Essentially, using the accumulator pattern accomplish the same effect.