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 githubfetch('api.github.com/user/AlbertoMontalesi').then( res => {// return the data in json formatreturn res.json();}).then(res => {// if everything went well, print the dataconsole.log(res);}).catch( err => {// or print the errorconsole.log(err);})
This is a very simple promise to fetch a user from GitHub and print it to the console. ...