The List type is used to explain the evaluation of argument lists (see 11.2.4) in new expressions, in function calls, and in other algorithms where a simple list of values is needed. Values of the List type are simply ordered sequences of values. These sequences may be of any length.
So, the standard doesn't have any limitations on the number of arguments and limited only by the memory.
Although there is nothing specific limiting the theoretical maximum number of arguments in the spec (as thefortheye's answer points out). There are of course practical limits. These limits are entirely implementation dependent and most likely, will also depend exactly on how you're calling the function.
function testArgs() {
console.log(arguments.length);
}
var argLen = 0;
for (var i = 1; i < 32; i++) {
argLen = (argLen << 1) + 1;
testArgs.apply(null, new Array(argLen));
}
Here are my results:
Chrome 33.0.1750.154 m: The last successful test was 65535 arguments. After that it failed with:
Uncaught RangeError: Maximum call stack size exceeded
Firefox 27.0.1: The last successful test was 262143 arguments. After that it failed with:
RangeError: arguments array passed to Function.prototype.apply is too large
Internet Explorer 11: The last successful test was 131071 arguments. After that it failed with:
RangeError: SCRIPT28: Out of stack space
Opera 12.17: The last successful test was 1048576 arguments. After that it failed with:
Error: Function.prototype.apply: argArray is too large
Of course, there may be other factors at play here and you may have different results.
And here is an alternate fiddle created using eval. Again, you may get different results.
Chrome 33.0.1750.154 m: The last successful test was 32767 arguments. After that it failed with:
Uncaught SyntaxError: Too many arguments in function call (only 32766 allowed)
This one is particularly interesting because Chrome itself seems to be confused about how many arguments are actually allowed.
Firefox 27.0.1: The last successful test was 32767 arguments. After that it failed with:
script too large
Internet Explorer 11: The last successful test was 32767 arguments. After that it failed with:
RangeError: SCRIPT7: Out of memory
Opera 12.17: The last successful test was 4194303 arguments. After that it failed with:
The List type is used to explain the evaluation of argument lists (see 11.2.4) in new expressions, in function calls, and in other algorithms where a simple list of values is needed....These sequences may be of any length.
So there is no limit in the standard. Of course, if your code runs in the real world, not in standards-land, there is obviously some limit (e.g. number of particles in the universe).
There are two ways to pass parameters to a function.
"Literally": f(a, b, c)
With apply(): f.apply(null, [a, b, c])
This latter way is the more realistic scenario for large argument lists.
Go to this JSFiddle to see the limits for each of these for your current browser.
This worked only if the length of the string was within the browser limit for the number of arguments that can be passed with Function.prototype.apply.
The function was later patched, making the function significantly more complicated.
FYI, there is an open Webkit issue filed in March 2012 that discusses the argument limit.
Just use an map (just an object) as a single parameter. You still get to use parameter names and can have as many arguments as you'd like. It guarantees you a theoretical infinite number of arguments you can pass in, however you obviously still remain bounded by heap space.