Avoid unintended modification of variables outside loops
Impact area
Manageability
Severity
High
Affected element
Lightning
Rule ID
SF-0058
Impact
A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the var
keyword can refer to a variable in an enclosing scope outside the nearest enclosing scope. This will overwrite the existing value of the variable in the outer scope when the body of the for-in is evaluated.
Remediation
Always use the var
keyword to declare variables inside for-in loops.
Time to fix
45 min
References
See the PMD documentation article: ScopeForInVariable.