Uninitialized local variables should not be accessed

  • UNINITIALIZED_LOCAL_VAR
  • Error
  • Medium
  • No tags

This rule applies when uninitialized local variables are accessed.

It is not likely to be a programmer's intent because accessing an uninitialized local variable results in undefined value.

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.

Was this documentation helpful?