November 2018
Beginner
132 pages
2h 57m
English
The await keyword helps us manage promises in a more procedural manner. The await keyword can be only used inside an async (asynchronous) function to resolve a promise. It helps us resolve promises just like the .then() function we saw earlier. Async... await is the cleanest way to control the flow of a modern asynchronous JavaScript application. An example can be seen here:
async function getPostCategory() { const postId = 123; const post = await Post.findById(postId); return post.category;}The preceding code block is essentially the same as the one shown here, using the .then() function:
function getPostCategory() { const postId = 123; return Post.findById(postId).then(post => { return post.category; });}Read now
Unlock full access