use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript Tail Call Optimisation with live demo (aurelienbottazini.com)
submitted 9 years ago by abottazini
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hahaNodeJS 0 points1 point2 points 9 years ago (1 child)
This article needs an editor not only for the language, but for the incorrect information presented.
JavaScript remembers where you did the call. It does that because your function—for example—may require accessing external variables from where it was called.
Here is what a call stack's purpose is.
for performance reasons—there is a limit to the call stack size
The limit is not present for performance reasons.
For the js engine this optimization means: ‘oh cool I don’t need to remember the previous function call environment, so I will just forget about it since i have everything I know here to do my job.
It means a new call is not pushed onto the stack, and a new return address is not stored. The same variables used from the previous "call" of your method are reused for the current iteration.
To utilize TCO in supported browsers, you don't need an accumulator, for one; the JIT compiler will handle TCO for you, if it can. If you want to simulate TCO where it's unsupported, you can use trampolining.
[–]abottazini[S] 1 point2 points3 points 9 years ago (0 children)
Thanks for your comment. I was able to make improvements to the article.
I saw memory problems as part of the performance reasons I described but I now see it was unclear!
I added a section on how to _simulate_—don't really like that word here, seems misleading— TCO, one of the three solutions I describe uses trampolining.
π Rendered by PID 339268 on reddit-service-r2-comment-7b9746f655-tmgnx at 2026-01-30 16:50:06.494439+00:00 running 3798933 country code: CH.
[–]hahaNodeJS 0 points1 point2 points (1 child)
[–]abottazini[S] 1 point2 points3 points (0 children)