CodeQL documentation

Duplicate variable declaration

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