From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Use async/await to handle asynchronous operations

Use async/await to handle asynchronous operations - JavaScript Tutorial

From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Use async/await to handle asynchronous operations

- Now that we've learned about promises, it's time to take things a step further. Promises are generally more readable and easier to work with than callbacks, but they're still not exactly the nicest looking syntax. The ultimate goal with asynchronous programming is to be able to write asynchronous code that looks synchronous. And promises, while better than callbacks, still kind of fall short in this respect. So that's why in ES6 and later versions, JavaScript provides us with a new async/await syntax that allows us to work with asynchronous operations in a manner that really resembles synchronous code. So instead of having to use callbacks or promises, both of which add a considerable amount of clutter to our code, we can now just use the await keyword in front of an asynchronous operation and get the result. And JavaScript takes care of all that complexity behind the scenes. So that might sound a little complicated, but one of the most important things to keep in mind with…

Contents