DEV Community

Madhavan G
Madhavan G

Posted on

JavaScript Callbacks.

A JavaScript callback is a function passed as an argument to another function, which is then executed (or "called back") at a later point in time to complete a specific task.

This mechanism is fundamental to JavaScript's event-driven and asynchronous programming model.

What is a Callback Function?
A callback function is a function passed as an argument into another function.

A callback function is intended to be executed later.

Types of Callbacks
Asynchronous Callbacks:
Asynchronous callbacks are executed at a later time, allowing the main program to continue running without waiting.

This is essential for preventing the application from freezing during long-running tasks like network requests.

Synchronous Callbacks
Synchronous Callbacks are executed immediately within the outer function, blocking further operations until completion.

Array methods like map(), filter(), and forEach() use synchronous callbacks.

Top comments (0)