ECMAScript 5.1, part 8.8
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.
I tried out a few browsers myself:
| apply() | literal
-----------------------------
Chrome 14 | 131155 | 32767
Chrome 35 | 126213 | 65535
Chrome 106 | 125625 | 62803
Firefox 30 | 500001 | 65535
Firefox 106 | 500001 | 65535
IE 9 | 254335 | 65533
IE 10 | 253667 | 65533
IE 11 | 252447 | 65533
Opera 22 | 126063 | 65535
Safari 4 | 524215 | 524205
Safari 7 | 65537 | 522159
I saw differences in many of these numbers on different machines, so I believe there are other factors at play besides just the browser (the OS?).
This is a real issue, not some trivia. A real-world example:
The Google Closure Library defined the following function.
goog.crypt.byteArrayToString = function(array) {
return String.fromCharCode.apply(null, array);
};
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.