DEV Community


Discussion on: Object Destructuring - but why?

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!