From the course: JavaScript: Async

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Understanding promises

Understanding promises - JavaScript Tutorial

From the course: JavaScript: Async

Understanding promises

- Callbacks are really handy for basic cases where we want to execute additional code after an asynchronous function completes. And as you might imagine, it's even possible to string callbacks together pretty much as far as we need to. However, when we start working with code that uses multiple chain callbacks, it can be hard to write code that's both well-organized and easy for humans to read, to solve this problem. Modern JavaScript supports promises, which allow us to string together multiple callbacks while maintaining well-organized and human readable code. A promise is an object that represents the eventual result of an asynchronous operation. A promise contains information about the operation and tracks its status. It has a state property which can be pending fulfilled or rejected, and it has a result property which starts as undefined and can be given a value based on the operation. When the operation is…

Contents