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 - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.