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
+24-13Lines changed: 24 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3140,32 +3140,43 @@ Other Style Guides
3140
3140
```
3141
3141
3142
3142
<a name="naming--uppercase"></a>
3143
-
- [23.10](#naming--uppercase) Use UPPERCASE for nested object namespacing, global variables, and constants.
3143
+
- [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a `const` (itcannotbereassigned), and(3) theprogrammercantrustit (anditsnestedproperties) toneverchange.
3144
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?- This is unnecessary, so uppercasing should not be used for constants within a file. It should be used for exported constants however.
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.
3145
3148
3146
3149
```javascript
3147
3150
// bad
3148
-
constnamespace=namespace || {};
3151
+
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';
3149
3152
3150
-
namespace.util.Widget= {
3151
-
// ...stuff...
3152
-
}
3153
+
// bad
3154
+
export const THING_TO_BE_CHANGED = 'should obviously not be uppercased';
3153
3155
3154
3156
// bad
3155
-
constapiKey='44b345234534t455245njkl523452-vbb9';
3157
+
export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables';
3156
3158
3157
-
// good
3158
-
constNAMESPACE=NAMESPACE|| {};
3159
+
// ---
3159
3160
3160
-
NAMESPACE.util.Widget= {
3161
-
// ...stuff...
3162
-
}
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