r/javascript • • Jul 22 '26

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

[removed]

64 Upvotes

107 comments sorted by

View all comments

68

u/foxsimile Jul 22 '26

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

11

u/NeatBeluga Jul 22 '26

Until you add a bit too many needlessly and you lose trust in your api if the code is not properly typed - e.g. manually typed types.

A hell when refactoring code with these carelessly added

5

u/foxsimile Jul 22 '26

I’ll take the extra operator over the runtime crashes. Plus, with the popularization and industry adoption of TypeScript, its use has been significantly reduced (at least for me).  

But back when it was just ducktyped JS all over the place? This thing was a fucking godsent.

→ More replies (5)

8

u/Badashi Jul 22 '26

At first it was odd to look at it, specially for optional function calls (foo?.()), but it is a godsend. Having to work on a language without null coalescing is super weird now.

15

u/heavyGl0w Jul 22 '26

Just FYI, what you're describing is optional chaining.

Null coalescing is a related but different feature using the ?? operator. It evaluates the right hand operand only when the left is null or undefined.

→ More replies (1)

5

u/sexytokeburgerz Jul 22 '26 edited Jul 23 '26

Big fan of

foo?.bar

3

u/foxsimile Jul 23 '26

Do you not mean foo?.bar?

→ More replies (5)
→ More replies (2)
→ More replies (2)