loading...

Discussion on: Default Parameters in ES6

Collapse
karfau profile image
Christian Bewernitz

This also works:

function destructedDefaults({foo="default"}={}) {
  return foo;
}
Collapse
sarah_chima profile image
Sarah Chima Author

Nice, but what's the purpose of the second curly brackets?

Collapse
karfau profile image
Christian Bewernitz

Well, it is the default for the first argument.
So you can call the function with no argument.
If it wouldn't be there, calling it without an argument, destruction leads to a TypeError of can not access property 'foo' of undefined.

Thread Thread
sarah_chima profile image