Chapter VI · Functions

Callback Functions

A callback function is passed into another function as an argument to be executed later.

01 How It Works

Think of leaving your phone number so a store clerk can call you when your order arrives.

Higher-order code delegates control back to the provided callback function upon completing an operation.

example.js
function processUser(callback) {
  callback("Alice");
}
processUser(name => console.log(name));
  1. 1. Write a function designed to receive another function parameter.

  2. 2. Pass a callback function reference during invocation.

  3. 3. Execute the callback inside the host function body.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
setTimeout(() => {
  console.log("Timer callback triggered");
}, 500);

Key Takeaway

Callbacks enable asynchronous execution flows and event-driven architectures.

Related Concepts