DEV Community

Discussion on: Breaking Down ES6: Default Parameters

Collapse
 
aleksikauppila profile image
Aleksi Kauppila

Hi Victoria, thanks for posting!

I don’t think default arguments are a good feature. Using default arguments is at least not a good practice and will produce bad designs.

  • There will be multiple ways to call a function
  • Default values will have implicit meaning that have to be explained with documentation or comments
  • it will become tempting to add more arguments with a default value to a function, which will require more conditional logic leading to a lot of complexity

Any thoughts? Thanks!

Collapse
 
torianne02 profile image
Tori Crawford

I definitely understand all of the points you are bringing up. Before jumping into each point, I just want to mention that I am a junior dev learning as I write. I began this series specifically to become more acquainted to the tools introduced by ES6 as that seems to be the popular version on most job descriptions.

Now, as to my thoughts about default parameters...I do think that implementing them in live code could definitely make things messy when trying to make sure arguments are being passed into the function properly. Having to keep in mind the specific order is not entirely easy, and yes, could require more comments and documentation.

As for your last point, I think that really falls on the developer. Being tempted to add more arguments to a function is all preference and self control.

With all that being said, I just learned about using the object spreader (introduced in ES8) for this purpose and it seems like a great tool to use!! Take a look at this article as it may interest you!

Thank you so much for adding to the discussion. :)

Collapse
 
aleksikauppila profile image
Aleksi Kauppila

That’s cool, we’re all learning every day :) thanks for the link, i’ll check it out. 👍