Sign in

What version of JS is used to determine whether a field exists in an object?

Dil edited in Wed, 02 Nov 2022
const Info = _global?.person?.info ?? {};

const Name = person?.name ?? '';

I usually use lodash / get to solve this kind of problem. I happened to see a big man using this method. Would you like to know the compatibility of this method?

3 Replies
commented on Wed, 02 Nov 2022

It has been determined that the next version will be added to the standard

yarn add @babel/plugin-proposal-optional-chaining -d.

Then configure it in Babel( babel.config.js Or babelrc) by adding @ Babel / plugin proposal optional chaining

commented on Wed, 02 Nov 2022

The alternative chain is still in the pipeline

commented on Thu, 03 Nov 2022

The Elvis operator