Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptrecursion and stack limitsSingle-choice MCQ

What does this trampolined version of a deep recursion print, and why does it not overflow the stack?

function trampoline(fn) { return (...args) => { let result = fn(...args); while (typeof result === 'function') result = result(); return result; }; } const sum = trampoline(function s(n, acc = 0) { return n === 0 ? acc : () => s(n - 1, acc + n); }); console.log(sum(100000));