callback
A function you pass to other code so it can call you back later, for example when an event happens or a timer fires.
In more detail
Event listeners, timers and many older asynchronous APIs take callbacks. The code that receives the callback decides when, and how often, to call it.
Examples
In the browser: addEventListener, MutationObserver, setTimeout and promise then() all take callbacks, and the event loop decides when each runs.Java: callbacks are usually lambdas or method references, such as .filter(User::active).In React, parents pass callbacks such as onToggle as props so children can report events upward.Related terms
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- event loop — The central loop of an asynchronous program that waits for events, such as timers firing or data arriving, and runs the matching callbacks.
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- lambda expression — A short anonymous function written inline and passed to other code, such as a condition for a filter.
- CompletableFuture — A Future that can be completed later and chained, letting you describe asynchronous steps such as transform, combine and recover without nesting callbacks.
- side effect — Anything a piece of code does besides returning a value, such as writing to a database, sending a message or changing a variable outside it.
- async and await — Language keywords for writing code that waits for slow work, such as a network call, without blocking a thread.
- one-way data flow — The React rule that data moves down the tree as props, and children report changes upward only by calling functions the parent passed them.
- useCallback — The React hook that returns the same function object between renders until one of its dependencies changes.
- closure — A function bundled with the variables it remembers from the scope where it was created.
- contextual typing — Type inference that flows from where a value is used, such as giving a callback's parameters the types the calling function expects.
- higher-order function — A function that takes a function as an argument or returns one, such as map, filter or a wrapper that adds retries.
- void — The return type of a function whose result has no meaning and should be ignored.
Taught in
- Decoupling: SQS, SNS, EventBridge And Step Functions — AWS Certified Solutions Architect – Associate (SAA-C03) Exam Prep
- MutationObserver: Reactive DOM Watching Without Polling — Frontend Architecture & Web Platform
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- requestAnimationFrame vs requestIdleCallback: High-FPS Work — Frontend Architecture & Web Platform
- The Streams API — Modern Java: Virtual Threads & High-Throughput Services
- Advanced Stream Operations — Modern Java: Virtual Threads & High-Throughput Services
- The ExecutorService — Modern Java: Virtual Threads & High-Throughput Services
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Microtask Queues: process.nextTick vs Promise Timing — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- SyntheticEvent System: Event Delegation in Modern React — React 19 & Modern Component Architecture
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture
- Avoiding Effect Antipatterns: Derived State And Events — React 19 & Modern Component Architecture
- useLayoutEffect vs useEffect: Painting And Synchronous Reads — React 19 & Modern Component Architecture
- useImperativeHandle: Controlled Ref Forwarding Boundaries — React 19 & Modern Component Architecture
- Lifting State Up: Colocation, Ownership, And Data Flow — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- Higher-Order Components And Render Props: Tradeoff Analysis — React 19 & Modern Component Architecture
- Rules of Hooks: Call Order, Hook Lists, And Fiber Storage — React 19 & Modern Component Architecture
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript