# Optional Chaining — A JavaScript journey #11

> Optional chaining is the future feature of JavaScript that I’m the most excited about. Here is why!

Source: https://antistatique.net/en/blog/optional-chaining-a-javascript-journey-11

Category: Development

# Optional Chaining — A JavaScript journey #11

Author(s)

[

![Yann](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Yann-G-300x300.jpg)



](/en/agence/yann)

[Yann](/en/agence/yann)9 July 2019

It's the future feature of JavaScript that I'm the most excited about: **[optional chaining](https://github.com/tc39/proposal-optional-chaining)**. And I'm sure you too without even knowing it. So, what is exactly _optional chaining_ and how it can really help to produce a cleaner code.

## The proposal

Two years ago, [Claude Pache](https://github.com/claudepache), [Gabriel Isenberg](https://github.com/gisenberg) and [Dustin Savery](https://github.com/dustinsavery) proposed _[optional chaining](https://github.com/tc39/proposal-optional-chaining)_ to TC39. Their goal is to reduce repetition and/or intermediate assignment in deep property access.

Take this (too) common examples:

```
// Repetitions
const email = person.contact && person.contact.email;
const elderName = person.children && person.children[0] && person.children[0].info && person.children[0].info.name;

// Intermediate assignment
const elder = person.children && person.children[0];
const elderInfo = elder && elder.info;
const elderName = elderInfo && elder.info.name;
```

Not very slight, right? Sure, there are other strategies, but with _optional chaining_, you'll be able to achieve the same behaviour doing something like:

```
// Repetitions
const email = person?.contact.email;
const elderName = person?.children?.[0]?.info.name;
```

Is it not sooo much better? With just a simple `?.`, you can test every level of your property access chain. This is the official proposal syntax:

```
obj?.prop        // optional static property access
obj?.[expr]      // optional dynamic property access
func?.(...args)  // optional function or method call
```

Finally, **it's not something completely new in programming language**; [C#](https://msdn.microsoft.com/en-us/library/dn986595.aspx), [Swift](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/OptionalChaining.html#//apple_ref/doc/uid/TP40014097-CH21-ID245), [CoffeeScript](http://coffeescript.org/#existential-operator) and others have similar features. We just have to wait a little bit more to see it in our plain JavaScript!

## Status

Actually, the proposal is in **stage 2**. It means it already pass the _proposal_ phase and it's now in _draft_. During this phase, the authors have to “precisely describe the syntax and semantics using formal spec language”. They already written the [initial spec text](https://tc39.es/proposal-optional-chaining/) and there is a fully working [Babel plugin](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining). So we can be optimistic about an upcoming **stage 3**.

## Using it now

_Babel plugin_ means that **you can use this feature right now**! Keep in mind that this is still not a final JavaScript feature, but this way you can test the concept and send feedback to the authors.

So, first install the dependencies:

```
yarn add --dev @babel/cli @babel/core @babel/plugin-proposal-optional-chaining
```

Then, in your `.babelrc`:

```
{
  "plugins": [
    ["@babel/plugin-proposal-optional-chaining", { "loose": false }],
  ]
}
```

And finally, just use your Babel to compile your \*code:

```
./node_modules/.bin/babel src --out-dir dist
```

_Take a look at the compiled code, it's fun to see how it's translated into old ES5_

## Conclusion

**It's coming soon and it's going to be great!** We can't say when it will be released, those things take time, but hopefully in 2020 if it's not in 2019. Keep in touch and try the Babel plugin in the meantime.

## More articles

Author(s)

[

![Anthony](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2024/11/anthony-1-300x300.png)



](/en/agence/anthony-salamone)

[Anthony](/en/agence/anthony-salamone)28 September 2026

### [Smashing Conference Freiburg 2026](/en/blog/smashing-conference-freiburg-2026)

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

[

![Smashing Conference Freiburg 2026 poster](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/assets/blog/smashing-2026.png)



](/en/blog/smashing-conference-freiburg-2026)

Author(s)

[

![Akira](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2025/03/akira-small-300x300.jpg)



](/en/agence/akira-kamata)

[Akira](/en/agence/akira-kamata)22 July 2026

### [Making of : “La nuit des Losers”](/en/blog/making-of-la-nuit-des-losers)

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

[

![Making of : “La nuit des Losers”](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/05/La-nuit-des-Losers-Teaser-1-768x576.png)



](/en/blog/making-of-la-nuit-des-losers)

Author(s)

[

![Pierre](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Pierre-300x300.jpg)



](/en/agence/pierre)

[Pierre](/en/agence/pierre)7 July 2026

### [Dark mode: necessity or trend](/en/blog/dark-mode-necessity-or-trend)

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

[

![Dark mode: necessity or trend](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/07/1-768x384.png)



](/en/blog/dark-mode-necessity-or-trend)
