What is the output of following code?
function xyz({name = "Rock", age = 20}) {
console.log(name, age);
}
xyz({name: "Joe"});
----o----
Output is:
"Joe"
20
This is an example of providing named arguments to a function. This is achieved using object destructuring. The value of arguments are mapped from the passed object. If a property is not passed(age
), the default value assigned is taken.