Promise.async function, the
await
keyword can be used to wait for a promise to resolve.async and await makes writing
Promise-based asynchronous code similar to normal code.async function foo() {
return 'foo';
}
foo()
Promise(status="fulfilled", result="foo")
await foo()
"foo"
async function bar() {
throw new Error('bar');
}
async function baz() {
try {
await foo();
await bar();
return '\u{1f389}';
} catch (e) {
return '\u{1f44e} ' + e;
}
}
await baz()
"👎 Error: bar"
The console allows you to interact with the course material and examples. Use the following keys:
A special logging function is also available: