Gentle introduction to Callbacks in Javascript

What are callbacks and what is a callback hell. In this short video I provide a simple explanation to callbacks.

A Callback is a function that is passed to another function.

Callbacks in Javascript
/*
Three ways to work with asynchronous operations in Javascript
1. Callbacks
2. Promises
3. async / await
*/

/*
Callback is a function that is passed to another function
*/

setTimeout(function () {
  console.log('Done')
}, 3000)

function myFunction(param1, callback) {
  // some operations
  console.log(param1)
  callback()
}

function myCallbackFunction() {
  console.log('Ankur')
}

myFunction(123, myCallbackFunction)

Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: