Callback: A function passed to another function to be called when an event completes. The classic pattern before promises and async/await. A callback is a function you pass to another function, to be called later. Often it runs when something finishes, such as a file read, a timer or a click.
In JavaScript, button.addEventListener('click', handleClick) passes handleClick as a callback. In PHP, array_map(fn ($x) => $x * 2, $numbers) passes a callback that is applied to every item.
What should you keep in mind with Callback?
For asynchronous work, callbacks nested inside callbacks quickly become hard to read and hard to handle errors in, which earned the name "callback hell". Promises and async/await solved most of that in JavaScript. Callbacks are still everywhere for events, sorting, filtering and hooks. Keep them short, and give them a name when they do more than one line of work.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.