What is a callback function?
sol- A callback function in JavaScript is a function passed as an argument to
another function. For ex-
// tellYourIntro() is the outer function
const tellYourIntro = (name, funct) => {
[Link](`Hello, I am ${name}`);
funct(); // Since we want to call the callback() function inside the greet
function below [Link](`Hi I'm ${name}`) therefore we have written it over here
};
// profession() is the callback function
const profession = () => {
[Link]("I am a software developer");
};
tellYourIntro("Asif", profession); // O/p is Hello, I am Asif
I am a software developer
The
Note - Whenever a callback function is passed as an argument inside another
function then there is no parenthesis otherwise in every situation the function is
always called with parenthesis.