0

Me and someone were debating over how recursive functions will cause a Maximum call stack size exceeded error. I made a function:

function e(){
   console.log("e");
   e();
}
e();

that uses a recursive loop to call itself. The person I was debating with said that it works because "It could be that your console.log's buffer is slow to write and so therefore it's just prolonging the stack overflow for quite a while." What exactly does this mean? I know that pretty much any code inside a recursive function prevents (or elongates the time until) a Maximum call stack size exceeded error.

Why is this true?

Reality
  • 637
  • 1
  • 6
  • 25
  • jeopardy: what is a [TCO](https://stackoverflow.com/questions/310974/what-is-tail-call-optimization) (or here: https://stackoverflow.com/questions/56036472/implement-javascript-function-using-tail-recursion/56037329#56037329)? – Nina Scholz Dec 12 '20 at 15:43
  • @NinaScholz I don't believe that Node supports TCO anymore (https://stackoverflow.com/a/30369729/14749127), and yet the code still runs indefinitely on Node without crashing, so I believe the picture might be a bit more nuanced than that, unless I'm missing something? – ouroboring Dec 12 '20 at 15:45
  • @NinaScholz Yes, but I want to know why the "console.log's buffer is slow to write" prevents the stack overflow (or prelongs it) – Reality Dec 12 '20 at 15:49

0 Answers0