The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K…

Follow publication

Member-only story

Callbacks in JavaScript

Photo by Christopher Gower on Unsplash

In the previous post, Synchronous vs Asynchronous Programming, we discussed the difference between Synchronous and Asynchronous programming in JavaScript. In this article, we will discuss what are Callbacks in JavaScript.

Callbacks

Callback is a function that is passed as an argument to another function and its execution is delayed until that function in which it is passed is executed.

Meaning, if I pass a function, let’s say function1 to another function, i.e., function2,then function1 will not be executed until function2 is executed.

Callbacks are a fundamental part of Functional Programming, and you may be already using them without knowing; methods like .map(), .filter(), and.reduce() all make use of callback functions. Let see an example:

In the above example, we iterate through the array arr, using the .map() method that accepts a callback function to modify the array elements.

In the above example, Function Declaration is used to define the function; you can also use arrow methods to pass a callback…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

No responses yet

Write a response