Just a simple short blog here. I used optional chaining for the first time because newest version @babel/preset-env has it included…

searchResults?.length > 0

I like this!

To show a comparison, this same line before was…

searchResults && searchResults.length > 0

This previous code pattern has annoyed me, because the entire page would fail at runtime and kind of crash the entire page. I have thought that the page would gracefully fail if an object was undefined and had no property. But nope.

Then I find that ES2020 will have optional chaining. I am really happy for optional chaining. The other updates make me think, “Oh cool”! But optional chaining makes be think, “Thank goodness!”

Clean code can still exist! At least with a few updates!