Skip to content

Commit 417ab20

Browse files
author
Walle Cyril
authored
Update tricks.md
1 parent 495ce5e commit 417ab20

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

js/tricks.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
## `Object.assign` is also useful on arrays
44

55
```
6-
const initialScores = [0, 0, 0];
7-
// player a, player b, total games
8-
const scores = [5, 2, 7];
6+
const initialScores = [0, 0];
7+
// player a, player b, total games played
8+
const state = [5, 2, 7];
99
10-
// reset scores
11-
Object.assign(scores, initialScores);
10+
// reset scores only
11+
Object.assign(state , initialScores);
12+
// state = [0, 0, 7];
1213
```
1314

1415
## `{}` can be used to create local scopes anywhere

0 commit comments

Comments
 (0)