# nullish coalescing

**URL:** <https://es.discourse.group/t/nullish-coalescing/2179>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [October 26, 2024, 10:57am UTC](https://es.discourse.group/t/nullish-coalescing/2179 "2024-10-26T10:57:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdanign](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jdanign/32/2271_2.png) [@jdanign](https://es.discourse.group/u/jdanign)\
**Post date:** [October 26, 2024, 10:57am UTC](https://es.discourse.group/t/nullish-coalescing/2179/1 "2024-10-26T10:57:32Z")

</div>

The nullish coalescing operator should consider undeclared variables and should return the right-hand operand instead of throwing an error.

This operator works as I say when a property of an object is not defined.  
`console.log(baz.firstProp ?? 'does not exist')`

Many languages ​​do this and it would greatly facilitate the syntax of this type of cases that can be very typical.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [October 26, 2024, 11:47am UTC](https://es.discourse.group/t/nullish-coalescing/2179/2 "2024-10-26T11:47:57Z")

</div>

I’m not convinced it is very typical - referencing an undeclared variable should only happen if you’re trying to reference a global that might not exist, which is pretty rare, and typeof guards it already for those cases.

What’s your use case for it?
