re: Recursion, Tail Call Optimization and Recursion. VIEW POST

TOP OF THREAD FULL DISCUSSION
re: There are implicit trade-off, such as losing the stack trace which could make things harder to debug. I think you have to keep in mind though, sof...
 

ES6 spec mandated TCO for mutually recursive functions as well that both call each other in tail call position.
Only Apple browsers have it implemented at the moment, Chrome implemented it but later removed it.

One notable part of the spec was that

function a(n){
  if (n<=0) return
  a(n-1)
}

would not get optimized, because there is an implicit return undefined after the last line.
I understand how that limitation came about, but I don't really see why they couldn't add a single "void" to the stack and then merrily recurse as if it's this:

function a(n){
  if (n<=0) return
  return a(n-1)
}

since the return value of the inner a is never used.

code of conduct - report abuse