Optional chaining in assignment LHS S1
- Stage: Stage 1
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
The proposal extends optional chaining syntax to the left-hand side of assignment operators, so that a property is assigned only when its base object is neither null nor undefined. It covers simple assignment, compound assignment, and logical assignment operators such as ??=.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Optional Chaining Assignment
Proposal to add support for optional chaining on the left of assignment operators: a?.b = c.
Status
- Champion: Nicolò Ribaudo
- Stage: 1
- Slides:
Motivation
It often happens that you need to assign to a property of an object, but only if that object actually exists.
The standard way to do it is by guarding the assignment using an if statement:
The language provides a way to read a property of an object but only if that object actually exists (obj?.prop = value), and developers have to remember that the same syntax is not supported when assigning.
Use cases
See this gist for examples of where this feature would be useful in the Babel and TypeScript code bases.
You can look for examples of where you may use optional chaining in your projects by searching for if \((.*?)\)[\s\n]*\{?[\s\n]*\1\.. This regular expression will have both false positives and false negatives, but it's a potential starting point.
Description
This proposal introduces the following syntax:
Implementations
- Babel (7.23.0)
- TypeScript (partially supported in the transform thanks to error recovery)
- V8
- JSC
- SpiderMonkey