| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/await | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 ..
* Some parts of this feature may have varying levels of support.
await Promise. async function .
[rv] = await expression;
expressionPromise .
rv Promise , , Promise.
await , async, Promise Promise . Promise . , await, Promise, Promise.
Promise , await .
await Promise .
function resolveAfter2Seconds(x) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(x);
}, 2000);
});
}
async function f1() {
var x = await resolveAfter2Seconds(10);
console.log(x); // 10
}
f1();
Promise, Promise.
async function f2() {
var y = await 20;
console.log(y); // 20
}
f2();
Promise , .
async function f3() {
try {
var z = await Promise.reject(30);
} catch (e) {
console.log(e); // 30
}
}
f3();
Promise try/catch .
var response = await promisedFunction().catch((err) => {
console.log(err);
});
// response undefined, Promise
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-async-function-definitions |
This page was last modified on 4 2024 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |