⏱ 0:02est. 3 min
Chapter 49- Closures and Callbacks
Notes
Example 1
function sayHiLater(){
var greeting = ‘Hi!';
setTimeout(function(){
console.log(greeting);
},3000)
}
sayHiLater(); //It will wait 3000 milliseconds and then prints hi
#BIGWORD - Callback function - A function you give to another function, to be run when the other function is finished. So the function you call (ie invoke) ‘call back' by calling the function you gave it when it finishes.
Example 2 - Callback function
function tellMeWhenDone(callback){
var a = 1000;
var b = 2000;
callback(); //the callback, it runs the function i give it.
}
tellMeWhenDone(function(){
alert(‘I am done');
});