1function add() {
2 var sum = 0;
3 for (var i = 0, j = arguments.length; i < j; i++) {
4 sum += arguments[i];
5 }
6 return sum;
7}
8
9add(2, 3, 4, 5); // 14
10
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
1function example() {
2 console.log(arguments);
3 console.log(arguments[0]);
4} // Console outputs an array of each argument with its value
5
6example('hi', 'hello');
7// Outputs:
8// ['hi', 'hello']
9// 'hi'
1function hello(name) {
2 alert("Hello " + name);
3}
4var name = "Person";
5hello();