- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path34_example-callback.js
More file actions
Latest commit
35 lines (24 loc) · 625 Bytes
/
Copy path34_example-callback.js
File metadata and controls
35 lines (24 loc) · 625 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
32
33
34
35
// example again callback-function
letadd=function(a,b){
returna+b;
}
letmultiply=function(a,b){
returna*b;
}
letcalculation=function(num1,num2,callback){
return`The result from ${num1} and ${num2} is ${callback(num1,num2)}`;
}
console.log(calculation(10,10,add));//20
console.log(calculation(20,20,multiply));//400
/*original
let calc = function(num1, num2, calcType){
// conditional
if(calcType === 'add'){
return num1 + num2;
}else if(calcType === 'multiply'){
return num1 * num2;
}
}
//access function
console.log(calc(20,20,'add')); //40
*/