Skip to content

Commit

Permalink
use const in rule "Use explanatory variables"
Browse files Browse the repository at this point in the history
per preceding rule "ES6 constants when variable values do not change"
  • Loading branch information
ChrisNikkel authored Jan 6, 2017
1 parent a22d1d9 commit 08dd958
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ for (var i = 0; i < MINUTES_IN_A_YEAR; i++) {
### Use explanatory variables
**Bad:**
```javascript
let cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
const cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
saveCityState(cityStateRegex.match(cityStateRegex)[1], cityStateRegex.match(cityStateRegex)[2]);
```

**Good**:
```javascript
let cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
let match = cityStateRegex.match(cityStateRegex)
let city = match[1];
let state = match[2];
const cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
const match = cityStateRegex.match(cityStateRegex)
const city = match[1];
const state = match[2];
saveCityState(city, state);
```
**[ back to top](#table-of-contents)**
Expand Down

0 comments on commit 08dd958

Please sign in to comment.