JavaScript continues rapid evolution, with exciting new features landing regularly that unlock cleaner code and richer web app capabilities. In this article, we’ll highlight some of the latest JavaScript additions you should learn to boost your developer skills in 2024.
Optional Chaining
Optional chaining (?.
) allows safely accessing nested object properties without lengthy null checks.
Instead of:
let email =
user &&
user.info &&
user.info.contact &&
user.info.contact.email;
We can directly access properties with ?.
:
let email = user?.info?.contact?.email;
If any intermediate property doesn’t exist, undefined is returned instead of a TypeError.
Optional chaining dramatically simplifies working with APIs and dynamic data shapes.
Nullish Coalescing
The nullish coalescing operator (??
) provides a shorthand for assigning default values if variables are null or undefined:
let username = user.name ?? ‘Anonymous’;