Glossary · Programming

Callback

A callback is a function passed as an argument to another function, which calls it later when an operation finishes or an event occurs.

Updated October 6, 2026

A callback is a function you pass to another piece of code so that it can be called back later, typically when an operation completes or an event occurs.

Why it matters

Callbacks are the basic mechanism for asynchronous and event-driven programming. Instead of waiting for a file read, a timer or a network response, the program continues and the callback runs when the result is ready. Browsers, Node.js, UI frameworks and many libraries rely on them. Deeply nested callbacks become hard to read and error handling gets scattered, often called "callback hell", which is why promises and async/await were introduced.

Example

setTimeout(() => {
  console.log("done");
}, 1000);
console.log("started");
// prints: started, then done after one second

setTimeout receives the arrow function and schedules it. The main code carries on and prints started first.

Common mistakes

  • Calling the callback twice, or never, on some code paths.
  • Ignoring the error argument in Node.js style (err, result) callbacks.
  • Expecting code after the asynchronous call to see the result.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.