0% found this document useful (0 votes)
3 views1 page

Understanding JavaScript Callback Functions

A callback function in JavaScript is a function that is passed as an argument to another function. In the provided example, 'profession' is a callback function used within 'tellYourIntro' to display a greeting and profession. It's important to note that when passing a callback, it should not be invoked with parentheses, as that would execute it immediately rather than passing it as a reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Understanding JavaScript Callback Functions

A callback function in JavaScript is a function that is passed as an argument to another function. In the provided example, 'profession' is a callback function used within 'tellYourIntro' to display a greeting and profession. It's important to note that when passing a callback, it should not be invoked with parentheses, as that would execute it immediately rather than passing it as a reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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.

You might also like