Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rephrase default value advice #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,23 @@ function paintCar(car) {
```
**[⬆ back to top](#table-of-contents)**

### Short-circuiting is cleaner than conditionals
### Use default arguments instead of short circuiting or conditionals

**Bad:**
```javascript
function createMicrobrewery(name) {
let breweryName;
if (name) {
breweryName = name;
} else {
breweryName = 'Hipster Brew Co.';
}
const breweryName = name || 'Hipster Brew Co.';
...
}

```

**Good**:
```javascript
function createMicrobrewery(name) {
const breweryName = name || 'Hipster Brew Co.'
function createMicrobrewery(breweryName = 'Hipster Brew Co.') {
...
}

```
**[⬆ back to top](#table-of-contents)**

Expand Down Expand Up @@ -428,25 +426,6 @@ function showList(employees) {
```
**[⬆ back to top](#table-of-contents)**

### Use default arguments instead of short circuiting
**Bad:**
```javascript
function writeForumComment(subject, body) {
subject = subject || 'No Subject';
body = body || 'No text';
}

```

**Good**:
```javascript
function writeForumComment(subject = 'No subject', body = 'No text') {
// ...
}

```
**[⬆ back to top](#table-of-contents)**

### Set default objects with Object.assign

**Bad:**
Expand Down