Disallow use of chained assignment expressions
Chaining the assignment of variables can lead to unexpected results and be difficult to read.
(function() {
const foo = bar = 0; // Did you mean `foo = bar == 0`?
bar = 1; // This will not fail since `bar` is not constant.
})();
console.log(bar); // This will output 1 since `bar` is not scoped.
This rule disallows using multiple assignments within a single statement.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule has an object option:
"ignoreNonDeclaration"
: When set to true
, the rule allows chains that don’t include initializing a variable in a declaration or initializing a class field. Default is false
.Examples of correct code for the { "ignoreNonDeclaration": true }
option:
Examples of incorrect code for the { "ignoreNonDeclaration": true }
option:
This rule was introduced in ESLint v3.14.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-multi-assign