Skip to content

Commit 59def82

Browse files
committed
Short-circuit don't use conditionals
1 parent 47f7e5a commit 59def82

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ locations.forEach((___location) => {
9494
```
9595
**[⬆ back to top](#table-of-contents)**
9696

97-
9897
### Don't add unneeded context
9998
If your class/object name tells you something, don't repeat that in your
10099
variable name.
@@ -126,6 +125,28 @@ function paintCar(car) {
126125
```
127126
**[⬆ back to top](#table-of-contents)**
128127

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+
129150
## **Functions**
130151
### Limit the amount of function parameters (2 or less)
131152
Use an object if you are finding yourself needing a lot of parameters.

0 commit comments

Comments
 (0)