A real-world example
In this section, we're going to move on from our contrived example and we're going to look at an example using two real HTTP APIs. Before we do, it's important to note that arrow functions (=>
) aren't the only functions that support async
. I just happen to use an arrow function (=>
). I could also use an ES5 function with the function
keyword; this works as well:
const getStatusAlt = async function (userId) { const user = await getUser(userId); const grades = await getGrades(user.schoolId); let average = 0;
I can save the file and I'm still going to get Jessica has 100%
printing:
I could also async
an ES6 object method, but I'm going to stick to an arrow function (=>
) here. Now, we're going to leave this file in the dust and we're going to move on to a brand new file for our real-world example.
Creating a currency-converter using the async/await function
This one is going to be called currency-convert.js
and, as you can probably guess by the name, we're going...