TypeScriptObjectoptional chaining
spread

optional chainingObject

nullish coalescing

Accesses nested properties safely; returns undefined if any part is null/undefined.

Syntax

obj?.prop?.nested

Example

Enter values below to update the example in real time.

const
user
profile
name
console
address
city
undefined
const user = { profile: { name: "Alice" } };
console.log(user?.profile?.name);   // "Alice"
console.log(user?.address?.city);   // undefined