TypeScriptオブジェクトoptional chaining
spread

optional chainingオブジェクト

nullish coalescing

中間値がnull/undefinedの場合undefinedを返します。

構文

obj?.prop?.nested

使用例

下記の値を入力するとサンプルに即時反映されます。

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