# no-implicit-global

Rule `sonarjs/no-implicit-global`. Variables should be declared explicitly

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1285 by reach, #586 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-implicit-global` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2703/) |

## Code examples

### Incorrect: the rule reports this

```js
function f(){
  i = 1;         // Noncompliant; i is global

  for (j = 0; j < array.length; j++) {  // Noncompliant; j is global now too
    // ...
  }
}
```

### Correct: the rule accepts this

```js
function f(){
  var i = 1;

  for (let j = 0; j < array.length; j++) {
    // ...
  }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-implicit-global": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-ignored-return](https://lintradar.dev/rules/sonarjs/no-ignored-return.md): Return values from functions without side effects should not be ignored
- [sonarjs/no-in-misuse](https://lintradar.dev/rules/sonarjs/no-in-misuse.md): "in" should not be used on arrays
- [sonarjs/no-ignored-exceptions](https://lintradar.dev/rules/sonarjs/no-ignored-exceptions.md): Exceptions should not be ignored
- [sonarjs/no-incompatible-assertion-types](https://lintradar.dev/rules/sonarjs/no-incompatible-assertion-types.md): Assertions comparing incompatible types should not be made
- [sonarjs/no-identical-functions](https://lintradar.dev/rules/sonarjs/no-identical-functions.md): Functions should not have identical implementations
- [sonarjs/no-incomplete-assertions](https://lintradar.dev/rules/sonarjs/no-incomplete-assertions.md): Assertions should be complete

---

Web page: https://lintradar.dev/rules/sonarjs/no-implicit-global. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
