# unicorn/no-null

> Disallow the `null` literal in favor of `undefined`

JavaScript has two values for "nothing". If you only use `undefined`, you need one check instead of two. Default parameters and destructuring defaults also apply to `undefined` but not to `null`.

Strict comparisons such as `x === null` are allowed by default, because you often need to check what an API returned.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-null" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"unicorn/no-null" = ["error", {
  checkStrictEquality = false,
  checkArguments = true,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
let selected = null;
```

Not reported:

{/* good */}
```js
let selected;

if (document.querySelector("dialog") === null) {
  selected = undefined;
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `checkStrictEquality` | `false` | Also report `x === null` and `x !== null`. |
| `checkArguments` | `true` | Report `null` that's passed to a function or a constructor. |

{/* bad {"options": [{"checkStrictEquality": true}]} */}
```js
if (selected === null) {
  selected = first();
}
```

{/* good {"options": [{"checkArguments": false}]} */}
```js
save(user, null);
```

## When not to use it

Many APIs return or expect `null`, like the DOM, JSON and databases. If your code talks to them a lot, this rule gets in the way.
