# null-dereference

Rule `sonarjs/null-dereference`. Properties of variables with "null" or "undefined" values should not be accessed

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
if (x === undefined) {
  console.log(x.bar); // Noncompliant; TypeError will be thrown
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/null-dereference": "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/non-existent-operator](https://lintradar.dev/rules/sonarjs/non-existent-operator.md): Non-existent operators '=+', '=-' and '=!' should not be used
- [sonarjs/object-alt-content](https://lintradar.dev/rules/sonarjs/object-alt-content.md): "<object>" tags should provide an alternative content
- [sonarjs/no-weak-keys](https://lintradar.dev/rules/sonarjs/no-weak-keys.md): Cryptographic keys should be robust
- [sonarjs/parameterized-tests](https://lintradar.dev/rules/sonarjs/parameterized-tests.md): Similar tests should be grouped in a single Parameterized test
- [sonarjs/no-weak-cipher](https://lintradar.dev/rules/sonarjs/no-weak-cipher.md): Cipher algorithms should be robust
- [sonarjs/post-message](https://lintradar.dev/rules/sonarjs/post-message.md): Origins should be verified during cross-origin communications

---

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