I have a nested object which may have stuff missing:
const unreliableObject = {
id: 10,
nestedObject: { // may be missing
id: 11 // may also be missing
}
}
Now say I want to get the inner id. I can do the following
const { nestedObject: { id: key = -1 } = {key: -1} } = unreliableObject;
console.log(key);
Is there a better way? Something where I'm not defining {key: -1}
twice, nor using an empty object (we have lint rules in place), and I still want to default key in that case.