File tree Expand file tree Collapse file tree 1 file changed +7
-28
lines changed
Expand file tree Collapse file tree 1 file changed +7
-28
lines changed Original file line number Diff line number Diff line change @@ -174,25 +174,23 @@ function paintCar(car) {
174174```
175175** [ ⬆ back to top] ( #table-of-contents ) **
176176
177- ### Short-circuiting is cleaner than conditionals
177+ ### Use default arguments instead of short circuiting or conditionals
178178
179179** Bad:**
180180``` javascript
181181function createMicrobrewery (name ) {
182- let breweryName;
183- if (name) {
184- breweryName = name;
185- } else {
186- breweryName = ' Hipster Brew Co.' ;
187- }
182+ const breweryName = name || ' Hipster Brew Co.' ;
183+ ...
188184}
185+
189186```
190187
191188** Good** :
192189``` javascript
193- function createMicrobrewery (name ) {
194- const breweryName = name || ' Hipster Brew Co. '
190+ function createMicrobrewery (breweryName = ' Hipster Brew Co. ' ) {
191+ ...
195192}
193+
196194```
197195** [ ⬆ back to top] ( #table-of-contents ) **
198196
@@ -431,25 +429,6 @@ function showList(employees) {
431429```
432430** [ ⬆ back to top] ( #table-of-contents ) **
433431
434- ### Use default arguments instead of short circuiting
435- ** Bad:**
436- ``` javascript
437- function writeForumComment (subject , body ) {
438- subject = subject || ' No Subject' ;
439- body = body || ' No text' ;
440- }
441-
442- ```
443-
444- ** Good** :
445- ``` javascript
446- function writeForumComment (subject = ' No subject' , body = ' No text' ) {
447- // ...
448- }
449-
450- ```
451- ** [ ⬆ back to top] ( #table-of-contents ) **
452-
453432### Set default objects with Object.assign
454433
455434** Bad:**
You can’t perform that action at this time.
0 commit comments