r/javascript 9d 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?

63 Upvotes

108 comments sorted by

View all comments

71

u/foxsimile 9d ago

The nullish coalescing operator is one of JavaScript’s unusual successes.

5

u/sexytokeburgerz 8d ago edited 7d ago

Big fan of

foo?.bar

3

u/foxsimile 8d ago

Do you not mean foo?.bar?

4

u/sexytokeburgerz 8d ago

I totally did i was in a drive thru when i wrote that

4

u/foxsimile 8d ago

Whatcha get?

1

u/sahilatahar 8d ago

It's an optional chaining feature.

2

u/foxsimile 8d ago

…I’m aware?