From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using async/await syntax

Using async/await syntax - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Using async/await syntax

- [Instructor] The next asynchronous feature of the JavaScript language that I want to talk about is a syntax called async/await. Async functions return a promise, and the resolved value of the promise will be whatever you return from the function. So let's take a look at this. We had our delay function from before. Which returned this new promise that set a timeout. So this looks pretty familiar. But I'm going to create here on line six, async function. So we know it's an async function because we use the async keyword right before the function arguments. And then what we're going to return from this is a console log message that's called zero seconds. Just for now. So let's call it and make sure that it's working. And now inside of this, we can say await delay one. So we're going to wait for one second. And then we'll console log another message. So remember our generator functions from before? We had that yield…

Contents