...

/

ES2017: Async and Await

ES2017: Async and Await

Async and await are going to be an important part of your coding knowledge, so let's learn how to use them.

We'll cover the following...

ES2017 introduced a new way of working with promises, called async and await.

 

Promise review #

Before we dive into this new strategy, let’s quickly review how we would usually write a promise:

Press + to interact
// fetch a user from github
fetch('api.github.com/user/AlbertoMontalesi').then( res => {
// return the data in json format
return res.json();
}).then(res => {
// if everything went well, print the data
console.log(res);
}).catch( err => {
// or print the error
console.log(err);
})

This is a very simple promise to fetch a user from GitHub and print it to the console. ...