Promises are a central mechanism for handling asynchronous code in JavaScript. You will find them in many JavaScript libraries and frameworks, where they’re used to manage the results of an action. The

1
fetch()

API is one example of promises at work. As a developer, you might not be familiar with creating and using promises outside of an existing product, but it’s surprisingly simple. Learning how to create promises will help you understand how libraries use them. It also puts a powerful asynchronous programming mechanism at your disposal.

Asynchronous programming with promises

In the following example, we’re using a

1
Promise

to handle the results of a network operation. Instead of making a network call, we just use a timeout:

To read this article in full, please click here


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *