What is a Callback Function?

There are still a bunch of different types of functions out there. You already know about arrow functions, but what about callback functions? Do you know what they are?

Callback functions are talked about a lot, but what exactly is a callback function? To keep it short, a callback function is basically a function that gets called when something happens. For example, when someone submits a form on your website, you need to run validations which means there are some functions that need to run in the background.

So when the user submitted the form, that action triggered the callback function that started all of the validations. If you weren’t using a callback function, your code would get hung on the validations and it would just sit there until someone submitted a form. That’s definitely not the way you want your website to behave.

A callback function let’s you run through your code until an event triggers it. Then the callback is run and then you go back to your original function. Here’s an illustration of a callback function in action:

You can see that the callback is waiting until something happens before it does anything and as soon as the callback function returns the code goes back to doing stuff. That’s really all there is to the callback function. Yes, that really is all it is.

Hopefully this helped clear up some of the jargon that you hear developers and programmers in general use. Just remember that most of these convoluted sounding terms are really just simple things being dressed up to look fancier.


You guys told me what you wanted so I’m doing it. Enough people said that they would come to a free web dev webinar, so I’m going to do one on November 18th. If you’re interested, just register here: https://bit.ly/2DaEZ0F Hopefully I’ll see you on the 18th! Whoo!