Await Expressions

Learn how await expressions assign the value of a promise to a variable and catch rejections.

Using await expressions

The await expressions are designed to make working with promises simpler. Instead of manually assigning fulfillment and rejection handlers, any promise used in an await expression behaves more like code in a synchronous function. The expression returns the fulfilled value of a promise when it succeeds and throws the rejection value when the promise fails. This allows us to easily assign the result of an await expression to a variable and catch any rejections using a try-catch statement. Here’s an example of using the fetch() API without await:

Get hands-on with 1200+ tech skills courses.