Simply Explained

Javascript Callback Function: Simply Explained

Le Van Tuan Long
Tech Front
3 min readMay 18, 2020

--

If you are coming from a different programming language and are learning Javascript, you might have come across the term callback.

With this article, I would like to give you the simplest explanation of what Javascript callback is. Before that let’s take a look at the definition of callback on MDN Web Docs

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action

Here is what I want you to remember:

Callback is a function passed into another function

Let’s look at an example of how we can use callback to improve the reusability of our function.

Without callback

Below is a piece of code without callback implementation, just a simple calculate function.

The issue with the above code is that the function calculate() is limited to just add and minus functionality.

--

--

Le Van Tuan Long
Tech Front

Technology writer. A software engineer by trade. Follow me on Twitter and Linkedin @levanify