What is a callback function in JavaScript?
A function passed as an argument to another function, to be called later. Callbacks are used for async operations (setTimeout, event listeners, fetch) and synchronous operations (map, filter, reduce).
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in What Are Callback Functions in JavaScript?
Because JS is single-threaded and synchronous. To handle async operations without blocking, it passes callbacks to Web APIs (setTimeout, fetch) or Node.js APIs (fs). The runtime calls the callback when the operation completes.
No. map, filter, and reduce call their callbacks synchronously. setTimeout, event listeners, and fetch call their callbacks asynchronously. The timing depends on the calling function, not the callback itself.
Yes. Every callback closes over variables from where it was defined. This is how a map callback can access outer variables, and how a setTimeout callback can access state from the enclosing function.
Still have questions?
Browse all our FAQs or reach out to our support team
