How many parameters are too many in JavaScript?

I came across the following question about StackOverflow: How many parameters are too many?

This made me wonder if there is a practical limit to the number of parameters of the 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(","); } 

It turns out that JavaScript imposes a practical limit of 65,536 parameters on functions.

However, what is 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:

  • Why is this a mismatch? Is this a mistake one at a time in language implementations?
  • Does the ECMAScript standard provide this limit for function parameters?
+5
source share
1 answer

The argument length is limited to 65536 https://bugs.webkit.org/show_bug.cgi?id=80797

There are different limits to the calculation of arguments, depending on how you are testing: http://mathiasbynens.be/demo/javascript-argument-count

+4
source

Source: https://habr.com/ru/post/1244909/


All Articles