Everything about Callback Function

Everything about Callback Function

Any function that is passed as an argument is called a callback function

A callback is a function that is to be executed after another function has finshed executing

Why do we need Callbacks?

For one very important reason — JavaScript is an event-driven language. This means that instead of waiting for a response before moving on, JavaScript will keep executing while listening for other events.

Callbacks are a way to make sure a certain code doesn’t execute until another code has already finished execution.

 const funA = () => {
    setTimeout(() => {
      console.log("This is Function : A");
      funB();
    }, 5000);
  };
  const funB = () => {
    console.log("This is Function : B");
  };

  funA();

In Above code, funB() function will call after funA() function finshes,it works after 5 seconds.

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment