Let's say I have this set up:
const objA = { name: "Jacob", email: "jacob@email.com" };
const objB = { lastName: "Smith" };
Why can I do this:
const lastName = objA.lastName || objB.lastName;
But not this?
const { lastName } = objA || objB;
Was able to re-create above example in dev tools.
My real world application: I have "normal" and "legacy" account roles, and after querying both types of roles, I'd like to be able to do:
const { schoolAdmin } = account || legacyAccount;
... but instead have to do:
const schoolAdmin = account.schoolAdmin || legacyAccount.schoolAdmin;
Which is admittedly not a big deal, but I feel like there's something I'm missing and that I could use destructuring here. Jr dev, sorry if this is a dummy question! (Sometimes there is no account, and sometimes there is an account that doesn't have the schoolAdmin role! Likewise with legacyAccount.)