+ 1
multiple parameters question
once you have put say, 2 parameters in a function after that point, MUST you use 2 for that function every time?
3 odpowiedzi
+ 11
[Edit] Forget my answer, you wanted Javascript. Sorry ;)
No. Two solutions for you:
1. You could overload the method, which means define another method with the same name but different parameters.
2. For parameters of the same type you can use varargs, example:
https://code.sololearn.com/c0Bf2pqc6ww1/?ref=app
0
You may use less or more than two parameters. For example, if you use less parameters than you announced, you must set the default value in function, otherwise not getted variable in function will have undefined value.
If you will send more than 2 parameters, it's will not cause errors.
0
Example of how to set default parameter
function multiply(a, b = 1) { return a*b; }
In this case you can call function as
multiply(3);
and return is will be 3