Skip to content

Commit d3e43f1

Browse files
zypA13510btmills
authored andcommitted
Docs: Update no-multi-assign explanation (#12615)
* Docs: Update no-multi-assign explanation Update description to explain "unexpected results". Also update examples to include ES6 syntax. * Update no-multi-assign.md Rephrased by @kaicataldo.
1 parent 272e4db commit d3e43f1

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

docs/rules/no-multi-assign.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Chaining the assignment of variables can lead to unexpected results and be difficult to read.
44

55
```js
6-
a = b = c = d;
6+
(function() {
7+
const foo = bar = 0; // Did you mean `foo = bar == 0`?
8+
bar = 1; // This will not fail since `bar` is not constant.
9+
})();
10+
console.log(bar); // This will output 1 since `bar` is not scoped.
711
```
812

913
## Rule Details
@@ -17,9 +21,9 @@ Examples of **incorrect** code for this rule:
1721

1822
var a = b = c = 5;
1923

20-
var foo = bar = "baz";
24+
const foo = bar = "baz";
2125

22-
var a =
26+
let a =
2327
b =
2428
c;
2529
```
@@ -32,11 +36,11 @@ var a = 5;
3236
var b = 5;
3337
var c = 5;
3438

35-
var foo = "baz";
36-
var bar = "baz";
39+
const foo = "baz";
40+
const bar = "baz";
3741

38-
var a = c;
39-
var b = c;
42+
let a = c;
43+
let b = c;
4044
```
4145

4246
## Related Rules

0 commit comments

Comments
 (0)