From d3e43f1c10c5e19f40e7b3d3944b87f1b0c9c075 Mon Sep 17 00:00:00 2001 From: Yuping Zuo Date: Sat, 21 Dec 2019 04:24:23 +0800 Subject: [PATCH] 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. --- docs/rules/no-multi-assign.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/rules/no-multi-assign.md b/docs/rules/no-multi-assign.md index 2da09ba0736..41bba9ad6a9 100644 --- a/docs/rules/no-multi-assign.md +++ b/docs/rules/no-multi-assign.md @@ -3,7 +3,11 @@ Chaining the assignment of variables can lead to unexpected results and be difficult to read. ```js -a = b = c = d; +(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. ``` ## Rule Details @@ -17,9 +21,9 @@ Examples of **incorrect** code for this rule: var a = b = c = 5; -var foo = bar = "baz"; +const foo = bar = "baz"; -var a = +let a = b = c; ``` @@ -32,11 +36,11 @@ var a = 5; var b = 5; var c = 5; -var foo = "baz"; -var bar = "baz"; +const foo = "baz"; +const bar = "baz"; -var a = c; -var b = c; +let a = c; +let b = c; ``` ## Related Rules