You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38
Original file line number
Diff line number
Diff line change
@@ -3139,6 +3139,44 @@ Other Style Guides
3139
3139
];
3140
3140
```
3141
3141
3142
+
<a name="naming--uppercase"></a>
3143
+
- [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a const, and (3) the programmer can trust it (and its nested properties) to never change.
3144
+
3145
+
> Why? This is an additional tool to assist in situations where the programmer would be unsure if a variable might ever change. UPPERCASE_VARIABLES are letting the programmer know that they can trust the variable (and its properties) not to change.
3146
+
- What about all `const` variables? - Thisisunnecessary, souppercasingshouldnotbeusedforconstantswithinafile. Itshouldbeusedforexportedconstantshowever.
3147
+
- What about exported objects?- Uppercase at the top level ofexport (e.g. `EXPORTED_OBJECT.key`) and maintain that all nested properties do not change.
3148
+
3149
+
```javascript
3150
+
// bad
3151
+
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';
3152
+
3153
+
// bad
3154
+
export const THING_TO_BE_CHANGED = 'should obviously not be uppercased';
3155
+
3156
+
// bad
3157
+
export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables';
3158
+
3159
+
// ---
3160
+
3161
+
// allowed but does not supply semantic value
3162
+
export const apiKey = 'SOMEKEY';
3163
+
3164
+
// better in most cases
3165
+
export const API_KEY = 'SOMEKEY';
3166
+
3167
+
// ---
3168
+
3169
+
// bad - unnecessarily uppercases key while adding no semantic value
0 commit comments