Skip to content

Commit b107a4d

Browse files
committed
callback function and higher older function
1 parent 814fec6 commit b107a4d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Callback function
3+
passed to another function as an argument &
4+
executed inside that function
5+
6+
Higher order function
7+
Accepts another function as an argument
8+
or return another function as a result
9+
10+
*/
11+
12+
13+
// this is a callbackfunction
14+
function morning(name){
15+
return `Good morning ${name}`;
16+
}
17+
18+
// higherorder function
19+
function greet(name, cb){
20+
const myName='Nakamura Ekuichi';
21+
// cb is argument and executed here
22+
//and then will resulted by this function as higher older function
23+
console.log(`${cb(name)} my name is ${myName}`);
24+
}
25+
26+
// remember callback function not invoke morning()
27+
//cz already exist in higher older function
28+
greet('Daisuke', morning);
29+
30+
// function greetMorning(name){
31+
// const myName = 'john';
32+
// console.log(`Good morning ${name}, my name is ${myName}`);
33+
// }
34+
35+
36+
// function greetAfternoon(name){
37+
// const myName = 'susan';
38+
// console.log(`Good afternoon ${name}, my name is ${myName}`);
39+
// }
40+
41+
// // run function
42+
// greetMorning('bobo');
43+
// greetAfternoon('peter');
44+

0 commit comments

Comments
 (0)