1function foo() {
2 for (var i = 0; i < arguments.length; i++) {
3 console.log(arguments[i]);
4 }
5}
6
7foo(1,2,3);
8//1
9//2
10//3
1/**
2 * My function description
3 * @param {String} a
4 * @param {String} b
5 * @param {Number} amount
6 * @example
7 * // returns "fooBar fooBar"
8 * myFunction('foo', 'Bar', 2)
9 * @returns {String}
10 */
11function myFunction(a, b, amount){
12 //do stuff
13}
14//Note that javascript is not a statically typed language and therefore you
15//will not recieve any syntax errors for passing in the wrong types.
16//The above code works in Visual Studio Code and intellisense.
1function sum(...values) {
2 console.log(values);
3}
4sum(1);
5sum(1, 2);
6sum(1, 2, 3);
7sum(1, 2, 3, 4);
8
9
10function sum(...values) {
11 let sum = 0;
12 for (let i = 0; i < values.length; i++) {
13 sum += values[i];
14 }
15
16 return sum;
17}
18console.log(sum(1)); //1
19console.log(sum(1, 2)); //3
20console.log(sum(1, 2, 3)); // 5
21console.log(sum(1, 2, 3, 4)); //10
1function functionName(parameter1, parameter2, parameter3) {
2 // code to be executed
3}