Interview Question

What are callbacks?

A callback is a function passed to code that decides when to call it.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

A callback is a function supplied for other code to call later or during an operation. • Array methods use callbacks synchronously. • Host APIs can call callbacks after events or timers. • A callback is a programming pattern, not a separate JavaScript type.

Example

Code
function run(callback) {
  callback('done');
}
run(console.log);
Output
done

Quick Revision

A callback is a function passed to code that decides when to call it.