Skip to content

Commit 6152b71

Browse files
committed
example again callback function
1 parent b107a4d commit 6152b71

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

34_example-callback.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// example again callback-function
2+
3+
4+
5+
6+
let add = function(a , b){
7+
return a + b;
8+
}
9+
10+
let multiply = function(a , b){
11+
return a * b;
12+
}
13+
14+
let calculation = function(num1, num2, callback){
15+
return `The result from ${num1} and ${num2} is ${callback(num1, num2)}`;
16+
}
17+
18+
console.log(calculation(10,10,add)); //20
19+
console.log(calculation(20,20,multiply)); //400
20+
21+
/*original
22+
23+
let calc = function(num1, num2, calcType){
24+
// conditional
25+
if(calcType === 'add'){
26+
return num1 + num2;
27+
}else if(calcType === 'multiply'){
28+
return num1 * num2;
29+
}
30+
}
31+
32+
//access function
33+
console.log(calc(20,20,'add')); //40
34+
35+
*/

0 commit comments

Comments
 (0)