November 2023: JavaScript's Async / Await vs. Promises - Which is Truly Better?
There is a right answer to this one, but it's up to you to decide if the juice is worth the squeeze.
Hi friends,
This newsletter is coming to you right after the US holiday of Thanksgiving where (for many of us) we gather with family and friends to reflect on all the things we are fortunate enough to have, and then start gearing up for the fast approaching end of the year.
How it’s already the end of 2023, I’m honestly not sure. When I look back, this year seems to have flown by (which I’m sure I say every year around this time).
I have one more newsletter of new content for you this month, and then in December I’ll do another “year in review” like I’ve done the last couple of years.
This month, I interviewed Dominik Dorfmeister on the LogRocket podcast PodRocket, and we went deep into the latest release of TanStack Query v5.
Dominik (aka @tkdodo on the Internet) has been a maintainer of the popular JavaScript-based state management, data fetching library TanStack Query (fma React Query) for quite some time, and version 5 dropped recently and it is super charged.
In our interview, Dominik shares the myriad of improvements to the library to make it easier and more intuitive for devs to use, smaller and faster than v4 by 20%, and better overall with new support for things like React Suspense, a brand new DevTools console for debugging, more fine grained data persistence, and even experimental support for React Server-rendered Components.
I’ve been a fan of TanStack since it was dubbed React Query, and with all the updates that v5 boasts, I hope you’ll give it a try in your next JavaScript app.
I also revisited a classic post I wrote a few years back on the debate (which still rages on today): which is superior JavaScript’s promises or async / await?
What started off as an innocent question from a developer on my team about whether we should continue using promises or refactor our entire codebase to use the newer async / await syntax, sparked a firestorm within the team, and led me down a path to determine if one was really superior to the other.
Spoiler alert: if you’re concerned with things like the speed of “microticks” in your own codebase, you want to reach for async / await whenever possible. Yes, it is syntactic sugar for promises, but the Chrome V8 developer team also optimized for async / await over promises, which makes the decision to refactor for enhanced performance an easier one in my book.
And I have to tell you, after using async / await for a number of years now, I’m a fan of the syntax. By and large, I prefer it to promises and .then()
, and I definitely prefer it to callbacks.
I hope you enjoyed this month’s edition of “Paige Codes.” Please share with your friends if you did.
See you again at the end of December with my end of year recap,
- Paige
Not subscribed yet? No worries.
I send a free email every month or so. You can check out my archive, or sign up below: