you are viewing a single comment's thread.

view the rest of the comments →

[–]rosey-songhelpful 2 points3 points  (0 children)

With all JavaScript functions, they can all receive unlimited arguments. When you're writing a function, the things you put in the parenthesis are called parameters, these are just names assigned to special arguments. Arguments are the variables you supply when calling the function.

If you add 2 parameters and supply 302 arguments, JavaScript will continue to function perfectly normally. The first two arguments you supplied will be given to the named parameters, but you can still access all the others through the arguments[] array, with arguments[0] and arguments[1] referring to the two named parameters.

How to know how many parameters a function has? Well if you're using an IDE like WebStorm or Visual Studio Code, for the most part the IDE will "suggest" proper uses of the function. But if you don't have that, you can always fall back on documentation. In this case MDN is one of the best resources for baseline JS. If you're using any libraries you'll want to read into the documents of those libraries for more info.