I have a requirement where I have to take a couple of values from a nested object which when not available, should be taken from a default object. For example consider the following object:
const objToDestructure={
someVal:3,
anotherVal:4,
outerObj:{}
}
If I want to take two field field1 and field2 from outerObj then what I was able to do was
const { someVal,anotherVal,outerObj = {field1:22,field2:33}}=objToDestructure;
const {field1,field2}=outerObj;
Is there anyway this can be shortened even more? I tried to do the following:
const { someVal,anotherVal,outerObj:{field1,field2} = {field1:22,field2:33}}=objToDestructure;
But I got both the values as undefined. Is there any reason why this won't work but the individual assignment does?