DEV Community

loading...

Discussion on: Object Destructuring - but why?

Collapse
lyrod profile image
Lyrod

You could talk about default value as well 😁

Collapse
christiankozalla profile image
Christian Kozalla Author

Sure, default parameters work with object destructuring as well!

If the object passed to myFunc has no name property, the default value "Unknown" will be logged (instead of undefined) 👍

const myFunc = ({ name = "Unknown", age }) => {
  console.log(name, age);
};
Enter fullscreen mode Exit fullscreen mode

Thanks for your suggestion, I'll update the post!