# no-undef-init

> Disallow initializing a variable to `undefined`

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`.
