---
title: "no-undef-init"
description: "Disallow initializing a variable to `undefined`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "eslint"
aliases: ["eslint/no-undef-init"]
kind: "suggestion"
category: null
default: "off"
fixable: "yes"
typeAware: false
deprecated: false
---

A `let` or `var` without a value already starts as `undefined`, so `= undefined` adds nothing.

`const` and `using` need a value, so they aren't reported.

`--fix` removes `= undefined` from `let name = undefined`. It leaves `var` and destructuring alone.

{/* 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]
"no-undef-init" = "error" # or "warn"
```

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

## Examples

Reported:

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

Not reported:

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

const missing = undefined;
```

## When not to use it

In a loop, `var current = undefined` resets the variable on every pass, and `var current` keeps the value from the previous pass. If your code relies on that, turn the rule off there or switch to `let`.
