Avoid the use of chained assignment expressions

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: javascript-code-style/no-multi-assign

Language: JavaScript

Severity: Notice

Category: Best Practices

Description

Assigning multiple variables at once can be hard to understand. Make one expression per assignment instead.

Non-Compliant Code Examples

var a = b = c;
var a = b = c = d;
let foo = bar = cee = 100;
a=b=c=d=e;
a=b=c;
a
=b
=c;
var a = (b) = (((c)));
var a = ((b)) = (c);
var a = b = ( (c * 12) + 2);
var a =
((b))
 = (c);
a = b = '=' + c + 'foo';
a = b = 7 * 12 + 5;
const x = {};
const y = x.one = 1;
let a, b;a = b = 1;
let x, y;x = y = 'baz';
const a = b = 1;
class C { field = foo = 0 }
class C { field = foo = 0 }

Compliant Code Examples

var a, b, c,
d = 0;
var a = 1; var b = 2; var c = 3;
var d = 0;
var a = 1 + (b === 10 ? 5 : 4);
const a = 1, b = 2, c = 3;
const a = 1;
const b = 2;
const c = 3;
for(var a = 0, b = 0;;){}
for(let a = 0, b = 0;;){}
for(const a = 0, b = 0;;){}
export let a, b;
export let a,
 b = 0;
// ignore non declaration option not supported
// const x = {};const y = {};x.one = y.one = 1;
// let a, b;a = b = 1
class C { [foo = 0] = 0 }
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: esther/docs-9518-update-example-control-sensitive-log-data