I came across the following question on StackOverflow: How many parameters are too many?
This got me thinking, is there a practical limit imposed on the number of parameters of a JS function?
test(65536); // okay test(65537); // too many function test(n) { try { new Function(args(n), "return 42"); alert(n + " parameters are okay."); } catch (e) { console.log(e); alert(n + " parameters are too many."); } } function args(n) { var result = new Array(n); for (var i = 0; i < n; i++) result[i] = "x" + i; return result.join(","); }
Turns out, JavaScript imposes a practical limit of 65536 parameters on functions.
However, what's interesting is that the error message says that the limit is 65535 parameters:
SyntaxError: Too many parameters in function definition (only 65535 allowed)
So, I have two questions:
Argument length limited to 65536 https://bugs.webkit.org/show_bug.cgi?id=80797
There are different argument count limits, depending on how you test: http://mathiasbynens.be/demo/javascript-argument-count
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.