-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargumentsObject.js
More file actions
31 lines (27 loc) · 860 Bytes
/
argumentsObject.js
File metadata and controls
31 lines (27 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function add() {
console.log(arguments[0], arguments[1], arguments[2]);
}
// add(); // undefined undefined undefined
// add(10); // 10 undefined undefined
// add(10, 20); // 10 20 undefined
// add(10, 20, 30); // 10 20 30
// add(10, 20, 'Priya', 25); // 10 20 30
function mul() {
if (arguments.length < 2 || arguments.length > 4) {
console.log("Multiplication can not be performed!");
} else if (arguments.length >= 2 && arguments.length <= 4) {
let x = 1;
for (let i = 0; i < arguments.length; i++) {
x = x * arguments[i];
}
console.log(`Multiplication:`,x);
} else {
console.log("Invalid Arguments");
}
}
mul(1);
mul(1, 2);
mul(1, 2, 3);
mul(1, 2, 3, 4);
mul(1, 2, 3, 4, 5);
// ** Argument object can not be used with arrow functions, filter, map, reduce, forEach.