Modern JavaScript features
Optional chaining, nullish coalescing, logical assignment, at(), Object.groupBy and more.
JavaScript has changed enormously since 2015 (ES6). A new edition of the standard ships every year, each adding small features that remove boilerplate and whole categories of bugs. You've already met many — let/const, arrows, classes, modules, destructuring. This lesson is a tour of the everyday modern features you'll see in any current codebase, grouped by the problem they solve.
Safely reading nested data: optional chaining ?.#
Data from APIs often has missing pieces. Before ?., reading deep properties needed long guard chains:
?. short-circuits: if the value on its left is null or undefined, the whole chain returns undefined instead of throwing. It works for methods and brackets too:
Use
?.where a value can legitimately be missing. Sprinkling it everywhere hides real bugs — ifordershould always exist, letorder.idfail loudly.
Better defaults: nullish coalescing ??#
|| falls back for any falsy value, which wrongly replaces 0, "" and false:
?? only falls back for null and undefined. Combine it with ?.:
Logical assignment: ??=, ||=, &&=#
A common idiom: lazily initialise a cache entry.
Relative indexing: at()#
Non-mutating array methods (ES2023)#
These are perfect for React state and any code that values immutability.
Grouping: Object.groupBy and Map.groupBy (ES2024)#
Easier object helpers#
String improvements#
Numbers#
Classes: fields, private members and static blocks#
Asynchronous features#
You'll study these properly in the async module:
(Save this as an .mjs file to run it with Node — top-level await only works in modules.)
Iterator helpers and Set methods (ES2025)#
The newest engines (Node 22+, current Chrome, Firefox and Safari) add lazy helpers to iterators and mathematical methods to Sets:
Iterator helpers are lazy: even though naturals() is infinite, only as many values as needed are computed.
Escaping text for regexes: RegExp.escape (ES2025)#
How do I know what I can use?#
- Browsers: check caniuse.com or MDN's compatibility tables. Everything up to ES2023 is supported in all current browsers.
- Node.js: use a current LTS (Node 24 at the time of writing) — node.green lists feature support.
- Build tools like Vite and TypeScript can compile newer syntax down for older targets, but they don't add missing built-in methods (like
Object.groupBy) — those need a polyfill (e.g.core-js) if you support old browsers.
Common mistakes#
- Using
||for defaults when0,""orfalseare valid values. - Overusing
?.and hiding genuine bugs. - Mixing
??with||or&&without parentheses —a ?? b || cis a SyntaxError; write(a ?? b) || c. - Assuming the newest features (ES2025) exist in every environment your users have.
What's next#
You've completed the language deep-dive. Next comes one of the most important topics in JavaScript: asynchronous code, starting with the event loop.
Check your understanding
Quick quiz
1.What does
user?.profile?.avatarevaluate to whenuser.profileisundefined?2.After
let count = 0; count ||= 10;, what iscount?3.What does
["a", "b", "c"].at(-1)return?
Finished reading?
Mark this lesson complete to track your progress.