Fast explicit tail calls in JavaScript

If you don't know what this is about, please have a look at an excellent background article on tail calls in JavaScript. Also my own early work on this might be helpful.

In LISP and other languages, tail calls are automatically optimized. In Clojure, there is an explicit keyword recur . Generally, programmers may well not know which "return" statements are optimized by the engine, and which not. This would lead to practical issues when debugging and optimizing [2009].

What about JavaScript?

As of 2018, progress is "slow" and the Chrome team has already removed the automatic self-recursion tail call optimization from its JavaScript engine.

Another possibility is to explicitly mark the tail calls that will be optimized. JavaScript extensions were proposed that add new keywords to the language [2013] [2016].

It turns out that we can do this explicit approach using today's JavaScript, without extending the language. fext.js demonstrates this.

Mutual recursion is supported. API doc and source on GitHub. Node.js package.

Update 2019-03-12: fext is now available in the D language as well.