Tail call optimization (TCO) in Node v6

$ node --harmony --use_strict
> function f() { return f(); }
undefined
> f()
$ node
> function f() { return f(); }
undefined
> f()
RangeError: Maximum call stack size exceeded
at f (repl:1:19)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
at f (repl:1:31)
node --harmony --use_strict 
> function f(x) { console.log(x); return f(x + 1); }
undefined
> f(0)
1
2
3
4
5
6
7
8
9
10
11
function f(x) { console.log(x); f(x + 1); }

--

--

Freelance programmer. Open source enthusiast. Author of https://jotai.org, valtio, etc. https://contact.axlight.com https://discord.gg/MrQdmzd

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store