Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit b7492ff

Browse files
committed
Update comparison recommendation
* Use shortcuts for boolean comparisons * Use explicit comparisons for strings and numbers
1 parent d0d2600 commit b7492ff

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,28 +1652,38 @@ Other Style Guides
16521652
```
16531653
16541654
<a name="comparison--shortcuts"></a><a name="15.3"></a>
1655-
- [15.3](#comparison--shortcuts) Use shortcuts.
1655+
- [15.3](#comparison--shortcuts) Use shortcuts for booleans, but explicit comparisons for strings and numbers.
16561656
16571657
```javascript
16581658
// bad
1659-
if (name !== '') {
1659+
if (isValid === true) {
16601660
// ...stuff...
16611661
}
16621662

16631663
// good
1664-
if (name) {
1664+
if (isValid) {
16651665
// ...stuff...
16661666
}
16671667

16681668
// bad
1669-
if (collection.length > 0) {
1669+
if (name) {
16701670
// ...stuff...
16711671
}
16721672

16731673
// good
1674+
if (name !== '') {
1675+
// ...stuff...
1676+
}
1677+
1678+
// bad
16741679
if (collection.length) {
16751680
// ...stuff...
16761681
}
1682+
1683+
// good
1684+
if (collection.length > 0) {
1685+
// ...stuff...
1686+
}
16771687
```
16781688
16791689
<a name="comparison--moreinfo"></a><a name="15.4"></a>

0 commit comments

Comments
 (0)