This article is aimed at the absolute beginners, but can also serve as a nice refresher for those of us who have been working with JS for a while.
What are callbacks?
A callback is a function that is passed into another function as an argument to be executed later. (Developers say you “call” a function when you execute a function, which is why callbacks are named callbacks).
Why use callbacks?
Callbacks are used in two different ways — in synchronous functions and asynchronous functions.
Callbacks in synchronous functions
If your code executes in a top to bottom, left to right fashion, sequentially, waiting until one code has finished before the next line begins, your code is synchronous.
Callbacks in asynchronous functions