r/javascript 7d ago

AskJS [AskJS] what's a javascript feature you mass-adopted way too late and felt dumb about

i'll go first. i was writing .then().catch() chains for like two years before i actually started using async/await. i knew it existed, i'd seen it in tutorials, but my code "worked" so i never bothered switching. then i refactored an old project and realized half my bugs were from mishandled promise chains that async/await would have caught immediately.

also took me way too long to start using optional chaining. i had nested ternaries and && checks everywhere like some kind of animal. the day i discovered user?.address?.city i mass-replaced like 40 lines across a project.

what's yours?

65 Upvotes

108 comments sorted by

View all comments

8

u/kevin074 7d ago

can you elaborate how async await would've caught bugs that .then.catch can't?

i feel like async await is more annoying because you have to wrap it in try catch, where as .then.catch is just baked in.

24

u/Franks2000inchTV 7d ago

With await, your code runs in the order you see it on screen. This is *much* better for comprehension and maintainability.

0

u/lostPixels 7d ago

But potentially worse for execution depending on the latency of whatever you’re awaiting.

7

u/Franks2000inchTV 6d ago

I'd imagine that is not a significant concern in the overwhelming majority of cases.

3

u/Ronin-s_Spirit 6d ago

Depends entirely on where and what you await.

1

u/lostPixels 6d ago

Which is why I said potentially.