bhylu.com

Advertisements

Function Callbacks

A callback is a function supplied for another operation to call. It can run immediately, once later, or repeatedly depending on the API.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

function visit(name, format) {
  return format(name);
}
console.log(visit("Mira", name => "Hello, " + name));

What happens

The callback formats the supplied name.