5 ms·
I don’t know their motivations, but having the same code work fine on one JS engine / browser / browser version, but totally stack overflow on another seems lik
by skrebbel 3y ago
I don’t know their motivations, but having the same code work fine on one JS engine / browser / browser version, but totally stack overflow on another seems like suboptimal to me. Explicit tail calls let you error out properly at the call site, Babel-style downcompile it to a loop of some sort, all that stuff.
- odyssey7 3y agoThis could be surprising, but the scenario already exists in production. In JavaScript's strict mode, Safari applies tail call optimization, but systems relying on V8 don't. To illustrate, the following code causes a stack overflow for me in both Google Chrome and in Node.js, but runs without issue in Safari. "use strict"; const countdown = (n) => n == 0 ? console.log('done') : countdown(n-1); countdown(100000);