Uninitialized local variables should not be accessed

  • UNINITIALIZED_LOCAL_VAR
  • Error
  • Medium
  • No tags

This rule applies when uninitialized local variables are accessed.

Accessing an uninitialized local variable results in undefined value so that it is not likely to be a programmer's intent.

Note: This rule does not apply when the uninitialized access appears after the variable declaration because it is often intended. In contrast, when the access appears before the declaration, it is highly likely to be a bug and also impedes code readability.

Noncompliant Code Example

View with compliant examples side by side
function foo() {
    clearTimeout(x); // UNINITIALIZED_LOCAL_VAR alarm
    var x = 1000;
}

Compliant Code Example

View with noncompliant examples side by side
function foo() {
    var x = 1000;
    clearTimeout(x);
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.