Skip to content
AgileLogics
5 min read

Advanced Language Features

Prerequisites: Arrays, Objects

A few features that show up constantly in real JavaScript codebases once past the basics:

// Destructuring: unpack values into variables
const { name, age } = user;
const [first, second] = fruits;

// Spread: expand an array/object into individual elements
const combined = [...fruits, "date"];
const updatedUser = { ...user, age: 26 };

// Optional chaining: safely access a possibly-missing property
console.log(user?.address?.city); // undefined, not an error, if missing

// Nullish coalescing: a default only for null/undefined
const displayName = user.name ?? "Anonymous";

Optional chaining (?.) and nullish coalescing (??) both avoid verbose manual if checks for "is this thing missing?"