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: js/red-javascript-style-guide/readme.md
+42-12Lines changed: 42 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,48 @@ d.toLocaleDateString();
202
202
// and other toString variants
203
203
```
204
204
205
+
### sets
206
+
207
+
Yes
208
+
209
+
```js
210
+
newSet();
211
+
```
212
+
213
+
#### When to use sets over arrays
214
+
215
+
* No duplicates are wanted
216
+
* The order is irrelevant
217
+
218
+
219
+
### maps
220
+
221
+
Yes
222
+
223
+
```js
224
+
newMap();
225
+
```
226
+
227
+
#### When to use maps over objects
228
+
229
+
In the following situations:
230
+
231
+
* Keys are something else than string or symbol
232
+
* Continuous adding and removal of key-value pairs
233
+
* Keys are unknown or can be anything
234
+
235
+
### absence of value
236
+
237
+
Use `undefined`, avoid `null`. `undefined` is the default that is already used by the language, for example: destructuring when missing, default return value, unassigned variable etc.
238
+
239
+
### booleans
240
+
241
+
`true` or `false`, use `Boolean` function to force cast to a boolean. Do not use `!!` to cast to a boolean. Leverage truthy values in `if` and `while`.
242
+
243
+
### promises
244
+
245
+
Prefer promises over callbacks for one-time futures. Use `async`, `await` , `Promise.all`.
246
+
205
247
### if else
206
248
207
249
Always use multi-line brackets.
@@ -243,10 +285,6 @@ import * as z from "./z.js";
243
285
consty=5;
244
286
```
245
287
246
-
### promises
247
-
248
-
Prefer promises over callbacks for one-time futures. Use `async`, `await` , `Promise.all`.
249
-
250
288
### Limit variable reach
251
289
252
290
Historically it has been done with an immediately invoked function expression, now that let and const are available and block scoped use a simple block. With an iife:
@@ -276,14 +314,6 @@ let nextSquare;
276
314
}
277
315
```
278
316
279
-
### absence of value
280
-
281
-
Use `undefined`, avoid `null`. `undefined` is the default that is already used by the language, for example: destructuring when missing, default return value, unassigned variable etc.
282
-
283
-
### booleans
284
-
285
-
`true` or `false`, use `Boolean` function to force cast to a boolean. Do not use `!!` to cast to a boolean. Leverage truthy values in `if` and `while`.
0 commit comments