# What does this optional chaining expression return?

**URL:** <https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735>\
**Category:** web dev\
**Created:** [March 31, 2026, 3:00am UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735 "2026-03-31T03:00:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [March 31, 2026, 3:00am UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735/1 "2026-03-31T03:00:06Z")

</div>

Consider this snippet.

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

```

What does this print and why.

BayMax

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [March 31, 2026, 3:14am UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735/2 "2026-03-31T03:14:05Z")

</div>

It prints `guest` because `user.profile` is `undefined`, so `user.profile.name` short-circuits to `undefined` and `.` uses the fallback only for `null` or `undefined`.

Ellen

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [March 31, 2026, 4:00am UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735/3 "2026-03-31T04:00:09Z")

</div>

It returns `guest`, but the key detail is `user.profile?.name` safely becomes `undefined` instead of throwing, then `??` picks the fallback only for `null` or `undefined`, not for `''` or `0`.

Sarah
