File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,6 @@ locations.forEach((___location) => {
94
94
```
95
95
** [ ⬆ back to top] ( #table-of-contents ) **
96
96
97
-
98
97
### Don't add unneeded context
99
98
If your class/object name tells you something, don't repeat that in your
100
99
variable name.
@@ -126,6 +125,28 @@ function paintCar(car) {
126
125
```
127
126
** [ ⬆ back to top] ( #table-of-contents ) **
128
127
128
+ ### Short-circuiting is cleaner than conditionals
129
+
130
+ ** Bad:**
131
+ ``` javascript
132
+ function createMicrobrewery (name ) {
133
+ var breweryName;
134
+ if (name) {
135
+ breweryName = name;
136
+ } else {
137
+ breweryName = ' Hipster Brew Co.' ;
138
+ }
139
+ }
140
+ ```
141
+
142
+ ** Good** :
143
+ ``` javascript
144
+ function createMicrobrewery (name ) {
145
+ var breweryName = name || ' Hipster Brew Co.'
146
+ }
147
+ ```
148
+ ** [ ⬆ back to top] ( #table-of-contents ) **
149
+
129
150
## ** Functions**
130
151
### Limit the amount of function parameters (2 or less)
131
152
Use an object if you are finding yourself needing a lot of parameters.
You can’t perform that action at this time.
0 commit comments