- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript async and await
JavaScript Asynchronous
JavaScript async and await
asyncandawaitlet you write asynchronous code that reads like ordinary code.
await pauses inside an async function until a promise settles.
Nothing else is blocked while it waits.
Example
Example
javascript
function delay(value) {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(value);
}, 10);
});
}
async function run() {
const name = await delay("Ada");
console.log("got " + name);
}
run();