2

You know, when there are too many function calls, such as infinite recursive function call, it gives an error, such as Uncaught RangeError: Maximum call stack size exceeded.

(function a() {a()})(); // Uncaught RangeError: Maximum call stack size exceeded

I want to know the way to get the maximum call stack size with Javascript. I think there would be only engine/runtime/browser-specific ways to do it, though.

  • 3
    What would you use that information for? – Ry- Aug 30 '17 at 16:24
  • 2
    Answered here: [Browser Javascript Stack size limit](https://stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit) – Rodrick Chapman Aug 30 '17 at 16:26
  • 2
    I don't think there is a fixed maximum. It depends on available memory, and that depends on hardware/software boundaries. There is no fixed maximum recursion level either, because it will depend what (how much) will get pushed on the stack with each recursion (or each function call for that matter). – GolezTrol Aug 30 '17 at 16:27
  • @GolezTrol: Indeed, while some architectures may have a fixed stack size, the amount available at any given moment depends on how deeply nested you already are. And some architectures may not have a fixed stack size at all... – T.J. Crowder Aug 30 '17 at 16:28
  • Create a recursive function using a try and catch block. It will be different depending on resources. http://2ality.com/2014/04/call-stack-size.html - try googling before asking. – zfrisch Aug 30 '17 at 16:28
  • @adeneo I was asking `the way to get the maximum call stack size`, not the way to get the maximum call stack size **error**. – Константин Ван Aug 30 '17 at 16:29
  • You just have to be careful with such a thing not to trigger tail-call optimization. @zfrisch: Axel's version there will get TCO'd. (**Edit**: Ah, he mentions that later.) The version in the answer to the linked question won't. – T.J. Crowder Aug 30 '17 at 16:29

0 Answers0