"Optional chaining" is really nice!
If you have written any JS you have probably had to do something like this this:
if (myObject && myObject.foo === 1)
in order to prevent things from going to shit if myObject happens to be undefined.
Optional chaining lets you do this:
if (myObject?.foo === 1)
It's made a whole lot of my code a whole lot less verbose. It's of course even better when accessing sub-sub-sub properties. More here:
There are of course ways for it to bite you in the ass. If you use eslint, you can tell it to complain at you if you are using it in an unsafe way:
@darius same 😀
Just a shame that it'll need a transpiler for most projects to older standards again for another decade 😑
If you are still supporting IE in 2021 you have other problems.
@darius It took me years to convert my team to using its equivalent in Ruby (they call it the "safe navigation operator") and I still feel gleeful every time I see it in review
Hometown is adapted from Mastodon, a decentralized social network with no ads, no corporate surveillance, and ethical design.