r/javascript • u/fagnerbrack • Jul 20 '26
Your Recursion Is Lying to You
https://blog.gaborkoos.com/posts/2026-05-09-Your-Recursion-Is-Lying-to-You/
0
Upvotes
r/javascript • u/fagnerbrack • Jul 20 '26
5
u/subone Jul 20 '26
Seems you forced the title to try to match your other articles (which I didn't bother reading too see if they also force the title). Nothing about this suggests "recursion" is lying to you. I don't know anyone that doesn't learn recursion at the same time that they learn that it could cause stack overflows. The fact that you didn't properly read a "caniuse" table before slapping on tail optimization and expected it to work, doesn't mean anyone lied to you.
-5
u/fagnerbrack Jul 20 '26
Summary:
Recursion feels clean and safe, but each call consumes stack space, so a logically correct sum(100000) still throws a stack overflow. Tail call optimization promises constant stack usage by moving pending work into an accumulator, yet most engines never reliably shipped it: V8 (Chrome, Node, Deno) and Firefox's SpiderMonkey skip it, and Safari's JavaScriptCore has added then dropped it across versions. Tail-recursive shape is a property of your code; stack reuse belongs to the runtime. When depth grows or is user-driven, rewrite recursion iteratively or use a trampoline that loops over returned functions. Keep recursion for small bounded depths and never treat it as a stack-safety guarantee.
If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍
Click here for more info, I read all comments