Skip to content

Callback functions: JS

Marie-Louise edited this page Nov 30, 2018 · 5 revisions

When you call or invoke a function you're asking for those lines of code to be executed immediately. This is also known as synchronist programming. When you use the function as a callback, it gets executed or invoked when it's supposed to in the future. This is known as asynchronous programming.

What is a callback? A callback is function like any other, but it's what you do with it that's different. Instead of calling the function manually, you're passing the name of the function to another function to execute.

function sayHello(){
console.log ('Hello');
}


function executeCallback (callback) {
callback();
}

executeCallback(sayHello);

Clone this wiki locally