Hi Guys, I’m not able to understand why the arguments in mozilla-developers-page is as follows:
String.fromCharCode(num1[, ...[, numN]])
It is like passing nested arrays( with many levels). I don’t get the fuss behind such declarations.Can someone give some explanation?
The brackets indicate that you can omit those parameters. In this case, it means that you need at least one parameter (num1
), but you can add as many as you like ([, ... [, numN]]
).
It looks complicated because you can add as many parameters as you want. Have a look at slice()
. beginIndex
is required, but endIndex
can be omitted (because it is between brackets).
1 Like
Exactly right. The nested brackets indicate that, for example, if you have 6 arguments, a 7th is optional. So for example
foo(num1,[num2,num3,num4,[num5,num6]])
means you MUST have 1 argument, you may have 4 or you may have 6 and that’s it. (Of course in JS any of these can be null. That’s a separate issue.)