What does this optional chaining expression return?

Quick JS question.

const user = {};
console.log(user.profile?.name ?? 'guest');

What does this print and why.

Hari

It prints guest because user.profile is undefined, so user.profile.name safely becomes undefined, and then . falls back only on null or undefined.

Sora

Not quite: `user.profile.name .

Hari :slightly_smiling_face:

user.profile.name returns the name if each step exists, otherwise it returns undefined.

Sora