# Optional property assignment?

**URL:** <https://es.discourse.group/t/optional-property-assignment/2144>\
**Category:** 💡 Ideas\
**Created:** [September 17, 2024, 4:21pm UTC](https://es.discourse.group/t/optional-property-assignment/2144 "2024-09-17T16:21:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [September 17, 2024, 4:21pm UTC](https://es.discourse.group/t/optional-property-assignment/2144/1 "2024-09-17T16:21:56Z")

</div>

I've tried to do `foo?.bar = value` as a replacement for `if (foo != null) foo.bar = value` a plainly embarrassing number of times, forgetting that it's not actually a thing. Most commonly, it's when there's multiple levels of indirection like in `foo?.bar?.baz = value` where I forget, since `foo?.bar?.baz` _is_ a valid expression to read, and `(foo?.bar).baz = value` is also a valid assignment.

Could optional assignment be added to 1. provide the same convenience available to property reads and 2. remove a clear syntactic gotcha I've been experiencing in practice?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [September 17, 2024, 4:31pm UTC](https://es.discourse.group/t/optional-property-assignment/2144/2 "2024-09-17T16:31:26Z")

</div>

Proposal for this is currently stage 1

> **[GitHub - tc39/proposal-optional-chaining-assignment: \`a?.b = c\` proposal](https://github.com/tc39/proposal-optional-chaining-assignment)**
>
> \`a?.b = c\` proposal

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [September 18, 2024, 3:01am UTC](https://es.discourse.group/t/optional-property-assignment/2144/3 "2024-09-18T03:01:19Z")

</div>

Oh crap, forgot that was a thing. I'm normally better at catching new stage 1 proposals. Thanks! 😅
