Async-Await
Learn about asynchronous programming and leverage promises in JavaScript.
StartKey Concepts
Review core concepts you need to learn to master this subject
Asynchronous JavaScript function
Resolving JavaScript Promises
Async Await Promises
Using async await syntax
JavaScript async…await advantage
Async Function Error Handling
JavaScript aysnc await operator
Asynchronous JavaScript function
Asynchronous JavaScript function
function helloWorld() {
return new Promise(resolve => {
setTimeout(() => {
resolve('Hello World!');
}, 2000);
});
}
const msg = async function() { //Async Function Expression
const msg = await helloWorld();
console.log('Message:', msg);
}
const msg1 = async () => { //Async Arrow Function
const msg = await helloWorld();
console.log('Message:', msg);
}
msg(); // Message: Hello World! <-- after 2 seconds
msg1(); // Message: Hello World! <-- after 2 seconds
An asynchronous JavaScript function can be created with the async
keyword before the function
name, or before ()
when using the async arrow function. An async
function always returns a promise.
Async Await
Lesson 1 of 1
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory