CodeQL documentation

Duplicate variable declarationΒΆ

ID: js/duplicate-variable-declaration
Kind: problem
Security severity: 
Severity: recommendation
Precision: very-high
Tags:
   - quality
   - maintainability
   - readability
Query suites:
   - 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ΒΆ

  • Ecma International, ECMAScript Language Definition, 5.1 Edition, Section 12.2. ECMA, 2011.

  • Β© GitHub, Inc.
  • Terms
  • Privacy