Skip to content

Latest commit

 

History

History
168 lines (166 loc) · 3 KB

variables.md

File metadata and controls

168 lines (166 loc) · 3 KB

Variables

Rule Description Snippet ESLint Default Link
init-declarations Enforce or disallow variable initializations at definition
var foo = 1;
var bar;

bar = 2;

Off [Link](http://eslint.org/docs/rules/init-declarations)
no-catch-shadow Disallow the catch clause parameter name being the same as a variable in the outer scope
var err = "x";
try {
    throw "problem";
} catch (err) {}
console.log(err)    // err is 'problem', not 'x'
Off [Link](http://eslint.org/docs/rules/no-catch-shadow)
no-delete-var Disallow deletion of variables
var x;
delete x;
Error [Link](http://eslint.org/docs/rules/no-delete-var)
no-label-var Disallow labels that share a name with a variable
var x = foo;
function bar() {
x:
  for (;;) {
    break x;
  }
}
Off [Link](http://eslint.org/docs/rules/no-label-var)
no-shadow-restricted-names Disallow shadowing of names such as `arguments`
var undefined = "foo";
!function(Infinity){};
function NaN(){}
Off [Link](http://eslint.org/docs/rules/no-shadow-restricted-names)
no-shadow Disallow declaration of variables already declared in the outer scope
var a = 3;
function b() {
    var a = 10;
}
Off [Link](http://eslint.org/docs/rules/no-shadow)
no-undef-init Disallow use of undefined when initializing variables
// Bad
var foo = undefined;
// Good
var foo;
console.log(foo === undefined);     // true
Off [Link](http://eslint.org/docs/rules/no-undef-init)
no-undef Disallow use of undeclared variables unless mentioned in a `/*global */` block
var a = someFunction();  // 'someFunction' is not defined.
b = 10;                  // 'b' is not defined.
Error [Link](http://eslint.org/docs/rules/no-undef)
no-undefined Disallow use of `undefined` variable
var undefined = "hi";
Off [Link](http://eslint.org/docs/rules/no-undefined)
no-unused-vars Disallow declaration of variables that are not used in the code
var y = 10;
y = 5;
// By default, unused arguments cause warnings.
(function(foo) {
    return 5;
})();
Error [Link](http://eslint.org/docs/rules/no-unused-vars)
no-use-before-define Disallow use of variables before they are defined
alert(a);
var a = 10;

f(); function f() {}

Off [Link](http://eslint.org/docs/rules/no-use-before-define)