Skip to content

eslint/no-restricted-globals Restriction

What it does

This rule allows you to specify global variable names that you don't want to use in your application.

Why is this bad?

Disallowing usage of specific global variables can be useful if you want to allow a set of global variables by enabling an environment, but still want to disallow some of those.

For instance, early Internet Explorer versions exposed the current DOM event as a global variable event, but using this variable has been considered as a bad practice for a long time. Restricting this will make sure this variable isn't used in browser code.

Example

If we have options:

json
"no-restricted-globals": ["error", "event"]

The following patterns are considered problems:

javascript
function onClick() {
  console.log(event); // Unexpected global variable 'event'. Use local parameter instead.
}

References

Released under the MIT License.