JavaScript Tail Recursion Optimization

By Xah Lee. Date: .

The sad story of JavaScript tail recursion in browsers

js tail call opt 2023-01-13 h3Fph
JavaScript tail call optimization status 2023-01-13 []

Google JavaScript removed Scheme Lisp's tail recursion optimization, because they think it's hard to debug for programers.

js tail call opt 2023-01-13 tPsMv
Google Chrome's JavaScript tail call optimization status 2023-01-13 []

some idiots propose to the JavaScript committee tc39 to add a special syntax to indicate that you want scheme lisp tail call optimization. This is like, are you sure you wanna do functional programing?

js tail tc39 proposal 2023-01-13 NwNtm
JavaScript tc39 proposal on JavaScript syntactic tail call 2023-01-13

I propose to the tc39 v8 JavaScript coders that we should add a syntax continue to a while loop. This can help warn infinite loop.

let i = 3;
while continue (i < 10) {

Tail Recursion Optimization in Programing Language Spec

however, Tail Recursion Optimization of Scheme LISP SICP fame, in a programing language spec, fundamentally violates a principle in lang design. i.e. it is a extra-functional spec, about implementation. This should only be done for system langs.

JavaScript in Depth