File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments