In JavaScript, all global variables are properties of the global object and vice versa. This feature leads to times when we accidentally use global variables without noticing them, e.g.
- Import statement is missing while a method of the same name happens to exist in the global object
- Moving code without moving the variable declaration, but the variable of the same name happens to be a global variable
This rule tries to check for these cases.
This rule cannot specify global variables. no-restricted-globals
can be used if required.
This rule has an object option:
"prototypeBuiltins"
(defaulttrue
) disallows properties from the prototype of Object"deprecated"
(defaulttrue
) disallows deprecated global DOM properties and methods"events"
(defaulttrue
) disallows the properties of the global object as an event target"ambiguousSingleWords"
(defaulttrue
) disallows uncommon, ambiguous global variables with single-word names
if (hasOwnProperty('foo')) {}
event.target.focus()
onbeforeunload = () => false
open(door)
location.href = ''
setTimeout(foo, 1000)
process.exit()
require('os')