> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-undef-init

[Added in v0.4.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.4.2)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-undef-init': 'error',
    },
  },
]);
```

## Rule Details

Disallow initializing variables to `undefined`.

In JavaScript, a variable that is declared and not initialized to any value automatically gets the value of `undefined`. It's therefore unnecessary to initialize a variable to `undefined`.

This rule aims to eliminate `var` and `let` variable declarations that initialize to `undefined`.

Examples of **incorrect** code for this rule:

```javascript
var foo = undefined;
let bar = undefined;
```

Examples of **correct** code for this rule:

```javascript
var foo;
let bar;
const baz = undefined;
```

## Differences from ESLint

The autofix preserves TypeScript type annotations and definite assignment tokens. ESLint's fix removes from the end of the variable name to the end of the declarator, which in TypeScript would also remove any type annotation:

```typescript
// ESLint autofix: let a: string = undefined; → let a;  (type annotation lost)
// rslint autofix: let a: string = undefined; → let a: string;  (type annotation preserved)
```

## Original Documentation

- [ESLint: no-undef-init](https://eslint.org/docs/latest/rules/no-undef-init)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-undef-init.js)
