Promise — then/catch syntax. async/await — synchronous-looking syntax.
Promise:
1// Promise chain2fetchUser(id)3 .then(user => fetchPosts(user.id))4 .then(posts => console.log(posts))5 .catch(err => console.error(err));
async/await:
1// async/await2async function getUserPosts(id) {3 try {4 const user = await fetchUser(id);5 const posts = await fetchPosts(user.id);6 console.log(posts);7 } catch (err) {8 console.error(err);9 }10}
Key differences: