We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 46a246e commit 17e26e8Copy full SHA for 17e26e8
1 file changed
js/tricks.md
@@ -0,0 +1,35 @@
1
+# JS tricks
2
+
3
+`Object.assign` is useful on arrays.
4
5
+```
6
+const initialScores = [0, 0, 0];
7
+// player a, player b, total games
8
+const scores = [5, 2, 7];
9
10
+// reset scores
11
+Object.assign(scores, initialScores);
12
13
14
+`{}` can be used to create local scopes anywhere
15
16
17
+const minMax = function (numbers) {
18
+ const results = [];
19
+ // variables localResult does not clash,
20
+ // independent blocks are used
21
+ {
22
+ const localResult = Math.min(...numbers);
23
+ results.push(localResult);
24
+ }
25
26
27
+ const localResult = Math.max(...numbers);
28
29
30
+ return results
31
+};
32
33
34
35
0 commit comments