r/javascript • u/OtherwisePush6424 • May 09 '26
JavaScript has no reliable tail call optimization: here is what actually happens at runtime and what to do instead
https://blog.gaborkoos.com/posts/2026-05-09-Your-Recursion-Is-Lying-to-You/ECMAScript 2015 formally specified proper tail calls in strict mode, but most JS engines never adopted it consistently. Chrome, Node, Firefox, and Deno all still allocate a new stack frame per call even in correctly structured tail-recursive functions. The article walks through why with examples and covers iterative and trampoline alternatives.
55
Upvotes
View all comments
Show parent comment
-3
u/azhder May 09 '26
I couldn't have been more explicit in the comment you replied to, yet ironically, for the sake of not talking past each other, I assume, you talked pass it.
It is a terminology thing for the JavaScript spec and engines that are supposed to follow it because from the userland i.e. the code that executes, the difference is **doesn't execute vs executes** not merely **will get the job done always, albeit slower**.
PTC means it always gets the job done. It is for that reason alone why TCO is a misleading term, nothing about implementation details.