Skip to main content

Posts

Featured

Async/await ECMAScript 6

This functionality is not introduced by ECMAScript 2015 but by ECMAScript 2017, and for use await, your function must be marked as async. When you use the keyword await before a promise, you pause the execution of the async function, wait for the resolution of the promise, and then resume the execution of the async function. The value returned is the value resolved by the promise. So we can write our previous example using async / await like this: async function getUserRightsAndUpdateMenu() { // getUser is a promise const user = await getUser(login); // getRights is a promise const rights = await getRights(user); updateMenu(rights); } await getUserRightsAndUpdateMenu(); And our code looks completely synchronous! Another pretty cool feature of async / await is the ability to use a simple try/catch to handle errors: async function getUserRightsAndUpdateMenu() { try { // getUser is a promise const user = await getUser(login); // getRights is a promise

Latest Posts

Job Support from India