Nested data often has missing pieces. A user may have no address, or an address with no city. Optional chaining lets you read user.address?.city without crashing. Use a clear default when the path is missing.
const city = user.address?.city ?? "Unknown";Treat only null and undefined as missing. An empty string is a real string, but you may choose to map it to a default for display.
Return a display label for a user's city.
interface Address { city?: string | null } and interface Person { name: string; address?: Address | null }.getCityLabel(p: Person): string.city exists and is not an empty string, return it.'Unknown'.