-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbackFunctions.js
More file actions
39 lines (32 loc) · 864 Bytes
/
Copy pathcallbackFunctions.js
File metadata and controls
39 lines (32 loc) · 864 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
36
37
/**
* Callback function - It is a function that will call another function that may/maynot be
* passed aa a parameter.
*
* Example - set Timeout - It will call the function when the specified time is passed.
*/
// Example 1
function sayHiLater(){
function greeting(){
console.log("I am callback function");
}
setTimeout(greeting, 3000);
}
sayHiLater();
// Example 2
/**
* A typical Example of callback function
* call the function which is passed as a parameter.
*
* @param {function} callback
*/
function tellMeWhenDone(callback){
var x = 100; // some work
var y = 200; // some more work
callback(); // It will return the function I gave
}
tellMeWhenDone(function(){
console.log("I am the first callback function");
});
tellMeWhenDone(function(){
console.log("I am the second callback function");
});