Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit b57f1d8

Browse files
committed
Add rules to styleguide
1 parent d817e66 commit b57f1d8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,25 @@ If your editor/IDE isn't listed above, a list of available plugins can be found
611611
612612
**[⬆ back to top](#table-of-contents)**
613613
614+
## Ternary
614615
616+
- [Ternary operators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) are fine so long as the statements are concise. Hint: If they need to span multiple lines you should use `if/else`.
617+
618+
```
619+
// bad
620+
age > 18 ? (
621+
alert("OK, you can go."),
622+
location.assign("continue.html")
623+
) : (
624+
stop = true,
625+
alert("Sorry, you are much too young!")
626+
);
627+
628+
// good
629+
age > 18 ? location.assign("continue.html") : stop = true;
630+
```
631+
632+
**[⬆ back to top](#table-of-contents)**
615633
616634
## Comparison Operators & Equality
617635
@@ -1216,6 +1234,16 @@ If your editor/IDE isn't listed above, a list of available plugins can be found
12161234
this._firstName = 'Panda';
12171235
```
12181236

1237+
- When defining a static/immutable `const` use uppercase
1238+
1239+
```
1240+
// bad
1241+
const timeoutDuration = 3000;
1242+
1243+
// good
1244+
const TIMOUT_DURATION = 3000;
1245+
```
1246+
12191247
- When saving a reference to `this` use `self`, but prefer `bind` ([Bind on MDN] (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind))
12201248

12211249
```javascript

0 commit comments

Comments
 (0)