← 返回首页
Duplicate variable declaration — CodeQL query help documentation CodeQL docs
CodeQL documentation
CodeQL resources

Duplicate variable declaration

ID: js/duplicate-variable-declaration Kind: problem Security severity: Severity: recommendation Precision: very-high Tags: - quality - maintainability - readability Query suites: - javascript-code-quality.qls - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

A variable declaration statement that declares the same variable twice is confusing and hard to maintain.

Recommendation

Remove one of the two declarations. When removing a declaration with an initializer, further changes may be necessary to ensure that the variable is correctly initialized.

Example

In the following example, the variable declaration statement declares the variable dom twice. The second declaration is unnecessary, and since it has no initializer it can simply be removed.

var dom, contactDetails, phonesTemplate, emailsTemplate, dom;

References