Combining ?. and ??
Pair safe access with sensible defaults.
Two Tools Together
Optional chaining ?. safely reads possibly-missing values, and nullish coalescing ?? supplies a default. Combined, they read deep data and fall back cleanly.
const user = {};
console.log(user.profile?.name ?? "Anonymous");The Common Pattern
The idiom a?.b ?? fallback reads safely and defaults if the result is nullish. This replaces verbose guard chains.
const data = { settings: { theme: "dark" } };
const theme = data.settings?.theme ?? "light";
console.log(theme); // "dark"