1 # Disallow Use of Chained Assignment Expressions (no-multi-assign)
3 Chaining the assignment of variables can lead to unexpected results and be difficult to read.
7 const foo = bar = 0; // Did you mean `foo = bar == 0`?
8 bar = 1; // This will not fail since `bar` is not constant.
10 console.log(bar); // This will output 1 since `bar` is not scoped.
15 This rule disallows using multiple assignments within a single statement.
17 Examples of **incorrect** code for this rule:
20 /*eslint no-multi-assign: "error"*/
24 const foo = bar = "baz";
31 Examples of **correct** code for this rule:
34 /*eslint no-multi-assign: "error"*/
48 This rule has an object option:
50 * `"ignoreNonDeclaration"`: When set to `true`, the rule allows chains that don't include initializing a variable in a declaration. Default is `false`.
52 ### ignoreNonDeclaration
54 Examples of **correct** code for the `{ "ignoreNonDeclaration": true }` option:
57 /*eslint no-multi-assign: ["error", { "ignoreNonDeclaration": true }]*/
68 Examples of **incorrect** code for the `{ "ignoreNonDeclaration": true }` option:
71 /*eslint no-multi-assign: ["error", { "ignoreNonDeclaration": true }]*/
80 * [max-statements-per-line](max-statements-per-line.md)