Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Abe Layee
8,378 PointsJs call back function
I understand that that call back functions are functions that call another function. My question is can anyone please explain this line below to me? I am lost where we passed callback as an argument and then we invoke the callback(). That part got me lost.
function sayHello() {
console.log("This is an example of callback function in javaScript");
}
function executeFunction(callback) {
callback(); // please explain this part to me. Is this a way of calling sayHello() function?
}
executeFunction(sayHello);
2 Answers
Andy Watts
20,836 PointsYes, you are correct, calling callback() runs the function that was passed in to the function as a parameter, so it will run the sayHello function.
Abe Layee
8,378 Pointsthank you