JavaScript Callbacks
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.
Functions as First-Class Citizens
In JavaScript, functions are objects. Because of this, functions can take functions as arguments, and can be returned by other functions. Functions that do this are called Higher-Order Functions (HOF). Any function that is passed as an argument is called a callback function.
Synchronous Callbacks
A synchronous callback is executed immediately. It is blocking. A great example of this is the Array.map() or Array.filter() methods. The engine waits for the callback to finish executing on every element before moving to the next line of code.
Asynchronous Callbacks
Asynchronous callbacks are often used to continue code execution after an asynchronous operation has completedβsuch as reading a file, making an HTTP request, or waiting for a timer. The most classic example is setTimeout().
View Full Transcript+
This section contains the full detailed transcript of the video lessons. It covers passing function references versus executing them, avoiding "Callback Hell" (Pyramid of Doom) where callbacks are nested multiple levels deep, and an introduction to why Promises were adopted in ES6.
