From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

What is the relationship between promises and callbacks?

What is the relationship between promises and callbacks?

From the course: Mastering Web Developer Interview Code

What is the relationship between promises and callbacks?

- [Instructor] Promises are objects in JavaScript that describe what is supposed to happen when a time based operation takes place. They supplement callbacks and provide structure, and certain guarantees that help make asynchronous code a little more dependable and easy to use. First, let's take a look at what a callback is. A callback is nothing more than a function passed as an argument. So this part right here is what we would refer to as a callback. In this case, we're calling a function, the function has no name. So it's actually an anonymous function, we could just as easily call another function that we've created somewhere else. Callbacks are common on asynchronous events, the callback will be executed when something happens in this case, whenever a click event takes place. Now there are a few problems with callbacks. The most notable is that callback code often suffers from clarity. More importantly, callbacks…

Contents