0% found this document useful (0 votes)
30 views

Callback Function

A callback function is a function passed as an argument to another function that is invoked inside the outer function. The document provides examples of passing functions like show as a callback to geeky, with geeky calling the callback to complete an action like logging output. Asynchronous functions do not wait for callbacks to finish before proceeding, while synchronous functions wait until callbacks are complete.

Uploaded by

dk1078451
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Callback Function

A callback function is a function passed as an argument to another function that is invoked inside the outer function. The document provides examples of passing functions like show as a callback to geeky, with geeky calling the callback to complete an action like logging output. Asynchronous functions do not wait for callbacks to finish before proceeding, while synchronous functions wait until callbacks are complete.

Uploaded by

dk1078451
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Callback Function

A callback function is a function (It can be any function Anonymous Function, Arrow
Function) passed into another function as an argument, which is then invoked inside
the outer function to complete some kind of routine or action.

function show(){ function show(a){


console.log(“I am show Function”); console.log(“I am show Function” + a);
} }
function geeky(callback){ function geeky(callback){
var a = 101;
callback();
callback(a);
} }
geeky(show); geeky(show);
function show(a){ function geeky(callback) {
console.log(“I am show Function” + a); var a = 101;
} callback(a);
function geeky(callback){ }
var a = 101; geeky(function(a) {
callback(a); console.log("I am show Function " + a);
} });
geeky(show);
function geeky(callback) {
function geeky(callback) { var a = 101;
var a = 101; callback(a);
callback(a); }
} geeky(a => console.log("I am show Function " + a));
geeky(function show(a) {
console.log("I am show Function " + a);
});
function show(){ setTimeout(function show(){
console.log(“I am show Function”); console.log(“I am show Function”);
} }, 5000);
function geeky(callback){
callback(); console.log(“End”);
}

geeky(show); Asynchronous - It never waits for each


operation to complete, rather it executes
console.log(“End”); all operations in the first GO only.

Synchronous - It waits for each


operation to complete, after that
it executes the next operation.

You might also like