Take this (too) common examples:
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:
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 :
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 and there is a fully working Babel plugin. So we can be optimistic about an upcoming stage 3.
Using it now
So, first install the dependencies :
Then, in your
And finally, just use your Babel to compile your *code:
*Take a look at the compiled code, it's fun to see how it's translated into old ES5
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.