claudepache/es-optional-chaining

Working with es6 const, let

a-x- opened this issue · 4 comments

a-x- commented

is there definition for the case:

const {fooBar} = res?.data?.buisnessData // equals const fooBar = _.get(res, 'data.buisnessData.fooBar')

@a-x- const/let and destructuring is orthogonal to optional chaining. In particular, const {fooBar} = anything is always equivalent to: const fooBar = anything.fooBar. Nothing new.

I don’t know what you mean by _.get(...).

a-x- commented
a-x- commented

thank you

In reality, as currently specced, const {fooBar} = <anything> is not equivalent to:

const fooBar = <anything>.fooBar

but to:

const tmp = <anything>
const fooBar = tmp.fooBar

which makes a difference when <anything> is an expression containing an optional chaining operator; see #7.