Chapter 2: Clean Code with ES6 Default Parameters & Property Shorthands
by Moritz Kröger
Creating a method also means writing an API — whether it’s for yourself, another developer on your team, or other developers using your project. Depending on the size, complexity, and purpose of your function, you have to think of default settings and the API of your input/output.
Default function parameters and property shorthands are two handy features of ES6 that can help you write your API.
ES6 Default Parameters
Let’s freshen up our knowledge quickly and take a look at the syntax again. Default parameters allow us to initialize functions with default values. A default is used when an argument is either omitted or undefined
— meaning null
is a valid ...
Get JavaScript: Best Practice now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.