Photo by Nicolas Thomas on Unsplash

A callback in javascript is a function that we pass into another function as an object. When we pass in a callback function into another function, that function now has access to the previously defined function. This can help us with asynchronous programming to make sure that one function doesn't run before another function is set to run. If one function relies on another function we can use the function that it relies on as a callback function.

If you've ever used .then() or async/await you’ll be pleased to know that underneath the hood both are using callbacks under the hood to await the completion of another function. Await will wait for a certain function to finish before it continues to run and .then() runs in the same way, its all about syntactical sugar. So if you wanted to, you could write your whole program using callbacks.