Skip to content

eslint/no-label-var Style ​

What it does ​

Disallow labels that share a name with a variable.

Why is this bad? ​

This rule aims to create clearer code by disallowing the bad practice of creating a label that shares a name with a variable that is in scope.

Example ​

Examples of incorrect code for this rule:

js
var x = foo;
function bar() {
  x: for (;;) {
    break x;
  }
}

Examples of correct code for this rule:

js
// The variable that has the same name as the label is not in scope.

function foo() {
  var q = t;
}

function bar() {
  q: for (;;) {
    break q;
  }
}

References ​

Released under the MIT License.