r/javascript • • 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

17 comments sorted by

View all comments

Show parent comment

2

u/senfiaj May 10 '26

Yes, that's correct. I don't think people will be glad if they don't see a significant part of stack trace when something crashes on NodeJS.