mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 03:26:22 +00:00
620 B
620 B
id | title |
---|---|
03f42b69-8321-443f-9d1d-fb7814999dd7 | JavaScript Async Functions |
Introduction
Async Functions1 is a new feature implemented in ES2017 to handle promises.
Syntax
Fulfilling a promise
async function asyncFunc() {
return 123;
}
asyncFunc().then((x) => console.log(x));
// 123
Rejecting a promise
async function asyncFunc() {
throw new Error("Problem!");
}
asyncFunc().catch((err) => console.log(err));
// Error: Problem!