⬅️ JavaScript 🔗 Stack Overflow
The ECMAScript version released in 2017 introduced syntax-level support for asynchronous functions. With the help of async
and await
, you can write asynchronous in a “synchronous style”. The code is still asynchronous, but it’s easier to read/understand.
async/await
builds on top of promises: an async
function always returns a promise. await
“unwraps” a promise and either result in the value the promise was resolved with or throws an error if the promise was rejected.
async function saveUsers(){
try{
let users = await getUsers()
saveSomewhere(users);
}
catch(err){
console.error(err);
}
}