Callbacks
Callbacks are the most basic form of JavaScript asynchronous programming. In the simplest terms, a callback is a function that gets called after another function completes. Callbacks are used to handle the response of an asynchronous function call.
In JavaScript, functions are treated like objects. They can be passed around as arguments, returned by functions, and saved into variables. A callback is a function object that is passed as an argument into a higher order function. A higher order function is simply a mathematics and computer science term for a function that takes one or more functions as arguments (callbacks) or returns a function. In JavaScript, a higher order function will take a callback as a parameter. Once the higher order finishes doing some form of work, such as an HTTP request or database call, it calls the callback function with the error or return values.
As mentioned in the Event Loop section in Asynchronous Programming, JavaScript is an event driven language...