+ 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?

4th Oct 2017, 5:09 PM
Michael
Michael - avatar
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
4th Oct 2017, 6:24 PM
Tashi N
Tashi N - avatar
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.
4th Oct 2017, 6:29 PM
Рафис Багаутдинов
Рафис Багаутдинов - avatar
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
4th Oct 2017, 6:33 PM
Рафис Багаутдинов
Рафис Багаутдинов - avatar