Callbacks
Discover how to pass functions as arguments to other functions and unlock powerful patterns.
Step 1 of 6
Functions can receive other functions
Since functions are values in JavaScript (just like numbers and strings), you can pass a function as an argument to another function. A function that's passed as an argument is called a callback — because the receiving function will 'call it back' at the right time. This is one of the most powerful patterns in JavaScript and the foundation for event handling, timers, array methods, and asynchronous code. You've already been using callbacks without knowing it: `setTimeout`, `.forEach()`, `.map()`, and `.filter()` all take callbacks.
Think of it this way: A callback is like telling a friend: 'When you finish cooking dinner, call me.' You're giving them a task (the callback function) to run at the right time. You don't cook the dinner yourself — you hand off the instructions and your friend executes them when the moment comes.
Web Standard
Callbacks are central to JavaScript's event-driven architecture. The browser uses callbacks for everything: click handlers, network responses, timers, and more. This pattern allows JavaScript to be 'non-blocking' — it can start a timer or network request, continue running other code, and then run the callback when the result is ready.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...