© Raju Gandhi 2019
R. GandhiJavaScript Nexthttps://doi.org/10.1007/978-1-4842-5394-6_14

14. Seemingly Imperative with async and await

Raju Gandhi1 
(1)
Columbus, OH, USA
 

When working with asynchronous operations, promises present a huge leap forward from using callbacks. However, promises present us with a specific domain-specific language (DSL) to work with, including but not limited to then, catch, and finally. This DSL, while easy, and fluent to work with, does not compose well with how we typically write code in JavaScript, which is imperative code. Consider the case of trapping errors—JavaScript affords us language constructs like try/catch that allow us to trap errors, and provide meaningful stack traces. Promises on the other hand, trap errors ...

Get JavaScript Next: Your Complete Guide to the New Features Introduced in JavaScript, Starting from ES6 to ES9 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.