Disallow Unused Variables (no-unused-vars)

Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.

Rule Details

This rule is aimed at eliminating unused variables, functions and variables in parameters of functions, as such, warns when one is found.

The following patterns are considered warnings:

//It checks variables you have defined as global
/*global some_used_var */

var x = 10;

var y = 10;
y = 5;

// By default, unused arguments cause warnings.
(function(foo) {
    return 5;

// Unused recursive functions also cause warnings.
function fact(n) {
    if (n < 2) return 1;
    return n * fact(n - 1);

The following patterns are not considered warnings:

var x = 10;

// foo is considered used here
myFunc(function foo() {
    // ...

(function(foo) {
    return foo;

Exporting Variables

In some environments you may use var to create a global variable that may be used by other scripts. You can use the /* exported variableName */ comment block to indicate that this variable may be used elsewhere.


By default this rule is enabled with all option for variables and after-used for arguments.

    "rules": {
        "no-unused-vars": [2, {"vars": "all", "args": "after-used"}]


This option has two settings:


This option has three settings:

The following code:

(function(foo, bar, baz) {
    return bar;

When Not to Use It

If you don’t want to be notified about unused variables or function arguments, you can safely turn this rule off.


This rule was introduced in ESLint 0.0.9.