A variable that is declared at function scope, but only used inside a single block should be declared in that block, and variables that are declared inside a block but used outside of it (which is possible with a `var`-style declaration) should be declared outside the block.

## Noncompliant Code Example

    function doSomething(a, b) {
      var i;  // Noncompliant; should be declared in if-block
      if (a > b) {
        i = a;
        console.log(i);
        var x = a - b;  // Noncompliant; should be declared outside if-block
      }

      if (a > 4) {
       console.log(x);
      }

      return a+b;
    }

## Compliant Solution

    function doSomething(a, b) {
      var x = a - b;

      if (a > b) {
        var i = a;
        console.log(i);
      }

      if (a > 4) {
       console.log(x);
      }

      return a+b;
    }