-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
93 lines (69 loc) · 2.09 KB
/
Copy pathfunction.js
File metadata and controls
93 lines (69 loc) · 2.09 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function myFunction(p1, p2) {
return p1 * p2;
}
let result = myFunction(4, 3);
console.log("Result of myFunction(4, 3):", result);
console.log("===================================");
function sum(...args) {
let sum = 0;
for (let arg of args) sum += arg;
return sum;
}
let x = sum(4, 9, 16, 25, 29, 100, 66, 77);
console.log("Sum of numbers using rest parameters:", x);
function findMax() {
let max = -Infinity;
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
x2 = findMax(1, 123, 500, 115, 44, 88);
console.log("Maximum number using arguments object:", x2);
function sumAll() {
let sum = 0;
for (let i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}
x = sumAll(1, 123, 500, 115, 44, 88);
console.log("Sum of all numbers using arguments object:", x);
console.log("===================================");
//Function expressions
let myFunction2 = function(a, b) {return a * b}
console.log("Result of myFunction2(4, 3):", myFunction2(4, 3));
const x3 = function (a, b) {return a * b};
let z = x3(4, 3);
console.log("Result of x3(4, 3):", z);
console.log("===================================");
//Arrow functions
let hello = () => {
return "Hello World!";
}
console.log(hello());
let hello2 = () => "Hello World!";
console.log(hello2());
let hello3 = (val) => "Hello " + val;
console.log(hello3("Everyone"));
let hello4 = val => "Hello " + val;
console.log(hello4("Everyone"));
let myFunction3 = (a, b) => a * b;
console.log("Result of myFunction3(4, 3):", myFunction3(4, 3));
const x4 = (a, b) => a * b;
let z2 = x4(4, 3);
console.log("Result of x4(4, 3):", z2);
console.log("===================================");
// This will not work
let myFunction4 = (x, y) => { x * y } ;
console.log(myFunction4(4,3));
// This will not work
//let myFunction5 = (x, y) => return x * y ;
// Only this will work
let myFunction6 = (x, y) => { return x * y };
console.log(myFunction6(4,3));
let myFunction7 = (x, y) => x * y ;
console.log(myFunction7(4,3));
console.log("===================================");