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.