I struggling to figure this one out. In the fiddle below how do i account for when itemChild may not be there? When i remove it i get the following error (index):49 Uncaught TypeError: Cannot read property 'cat' of undefined
const item = {
name: "firstItem",
color: "red",
shape: "square",
size: "big",
itemChild: {
cat: "category1",
age: "10"
}
}
let {
name,
color,
shape,
size,
itemChild = {},
itemChild: {
cat = "",
age = ""
}
} = item;
if (itemChild) {
console.log("Child", cat, age);
} else {
console.log("Parent", name, color);
}