In the following exercises, we’re going to take what we’ve learned about chaining Promises and make it simpler using functionality introduced in ES8:
await. You read that right, you did the hard part already. Now it’s time to make it easier.
The structure for this request will be slightly different. We will use the new keywords
await, as well as the
Take a look at the diagram on the right.
Here are some key points to keep in mind as we walk through the code:
asynckeyword is used to declare an
asyncfunction that returns a promise.
awaitkeyword can only be used within an
awaitsuspends the program while waiting for a promise to resolve.
- In a
try...catchstatement, code in the
tryblock will be run and in the event of an exception, the code in the
catchstatement will run.
getData() function to the right to see how the request can be written using
Move on to the next exercise when you’re ready!