Consider the following code:
function foo({
item1 = 'a',
item2 = 'b',
item3 = {x: 1, y: 2}
} = {}) {
console.log(item1,item2,item3.x,item3.y)
}
If you call foo() you will get an object with the defaults for item1, item2, and item3. You can also call foo({item1: 'm', item2: 'n'}) and your result will include the default item3 of {x: 1, y: 2}. However, if you call:
foo({item1: 'm', item2: 'n', item3: {x: 99}})
you'll get undefined for item3.y in the scope of the function foo.
So:
Is there a way to get individual defaults for the nested properties of item3 in a scenario such as this?
item1,item2anditem3properties of your argument object, to which you assigned the default{}.