10

In Chrome and Node, the following code throws an error:

function noop() {}
var a = new Array(1e6)
// Array[1000000]
noop.apply(null, a)
// Uncaught RangeError: Maximum call stack size exceeded

I understand why it might be a Bad Idea to pass 1 million arguments to a function, but can anyone explain why the error is Maximum call stack size exceeded instead of something more relevant?

(In case this seems frivolous, the original case was Math.max.apply(Math, lotsOfNumbers), which is a not-unreasonable way of getting the max number from an array.)

2
  • …because function arguments are stored on the stack? Commented Feb 16, 2017 at 2:18
  • Well, yes, that's the piece of info I was missing :) Commented Feb 16, 2017 at 3:44

1 Answer 1

13

Function arguments are put on the stack. You're trying to put a million arguments onto the stack, and that's more than the maximum stack size. So the error message is very relevant to the reason for the error.

Sign up to request clarification or add additional context in comments.

1 Comment

For anyone wanting more specific browser stack size limitations, I found this: stackoverflow.com/questions/7826992/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.