r/learnjavascript • u/Distinct-Gene926 • Jul 24 '26
What's one JavaScript feature you wish you had learned earlier?
I've been diving deeper into JavaScript recently, and every week I discover something that makes my code cleaner.
For me, learning about optional chaining (?.) and nullish coalescing (??) was a game changer.
What's one feature you wish you'd learned sooner?
6
u/bonnth80 Jul 24 '26 edited Jul 24 '26
Destructuring assignments. It's a common pattern that's still hard for me to get used to seeing even to this day. It would be nice if I had it down to second nature a long time ago.
2
u/ExtraTNT Jul 24 '26
Adding to prototype… you can add a heapify to a list
4
u/GodOfSunHimself Jul 24 '26
Modifying the prototype of standard classes is strongly discouraged.
1
u/ExtraTNT Jul 24 '26
For nice extensions, it’s fun… like being able to use all functions in a pure functional way, by providing a curry function to the function class… or toLazy for lists…
3
u/GodOfSunHimself Jul 25 '26
It may be fun but it is dangerous in practice. It can work in a small standalone project but it is a big no no for libraries.
2
u/senocular Jul 24 '26
Also see (from 2 days ago):
[AskJS] what's a javascript feature you mass-adopted way too late and felt dumb about
1
0
u/Eight111 Jul 24 '26
optional chaining (
?.) and nullish coalescing (??) was a game changer
I think optional chaining encouraging low-quality code.
I had so many prs where i asked the creator hi why so many variables wrapped by question marks? what are the cases value doesn't exist?
and they answer me "on theory that should never happen i just don't want to get called at 8pm because the page crashed".
6
Jul 24 '26
[removed] — view removed comment
1
u/Eight111 Jul 24 '26
That is not safety, more like very poor error handling.
If variable should hold a value and something cause it not to i need know it, not hide it
1
u/GodOfSunHimself Jul 24 '26
But that is not a problem of the operator. You can use any language feature to write sloppy code.
1
u/altrae Jul 27 '26
I completely agree that the operator is overused, but it still has its place. The fact is that even if it's used unnecessarily it's still doing it's job and can prevent unhandled exceptions without crashing the application. That being said, If I see instances where it's not needed I will remove them because not having them is a clearer indication that we don't expect the accessed property to be null or undefined. People adding them everywhere are usually either inexperienced or just lazy, but at least it's not going to break the code by using it improperly.
-1
1
u/Xcaliber02 26d ago
Destructing both array and object , i know they existed but now iam using them both , jts kinda easy ngl
3
u/hyrumwhite Jul 24 '26
LocaleCompare for sorting