# biome complexity/noUselessUndefinedInitialization: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: biome 2.5.15
- Rule: complexity/noUselessUndefinedInitialization (tool labels the fix: safe, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The fix removes the explicit `= undefined` initializer from a `var` declaration inside a loop. Because `var` is function-scoped, the original code re-initialized `a` to `undefined` on every iteration, while the fixed code only declares `a` once (hoisted) and retains its value from the previous iteration, changing the printed output.
- Program: minimized from 11 to 8 lines

## Reproducer

```js
function scopeTest() {
  for (let i = 0; i < 2; i++) {
    var a = undefined; // Rule triggers twice
    console.log('Iteration', i, 'a =', a);
    a = i * 10;
  }
}
scopeTest();
```

## Commands

```sh
node prog.js
bunx @biomejs/biome lint --only=complexity/noUselessUndefinedInitialization --write prog.js
node prog.js
```

## Observed

```
stdout before:
Iteration 0 a = undefined
Iteration 1 a = undefined
stdout after:
Iteration 0 a = undefined
Iteration 1 a = 0
```

## Diff applied by the fix

```diff
--- orig.js	2026-10-22 13:26:11.228730344 -0400
+++ fixed.js	2026-10-22 13:26:13.430766808 -0400
@@ -1,6 +1,6 @@
 function scopeTest() {
   for (let i = 0; i < 2; i++) {
-    var a = undefined; // Rule triggers twice
+    var a ; // Rule triggers twice
     console.log('Iteration', i, 'a =', a);
     a = i * 10;
   }
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original code declares `var a` with an explicit initializer of `undefined`, which executes on each loop iteration due to hoisting but re-evaluates the assignment each time, resetting `a` to `undefined` before logging. The fix removes the initializer, leaving only the declaration `var a;`—which still hoists and initializes `a` to `undefined` once at function entry—but does not reassign it per iteration. Thus, on the second loop, `a` retains its prior value (`0` from `i * 10` when `i=0`) instead of being reset to `undefined`, changing the logged output. The behavior differs because the initializer’s per-iteration execution is lost.

## Upstream search

Queries: "noUselessUndefinedInitialization fix", "complexity noUselessUndefinedInitialization variable declaration", "var initialization to undefined in loop body", "removing redundant undefined assignment preserves value"

- duplicate: https://github.com/biomejs/biome/issues/11938
  Same rule removing `= undefined` from a `var` declaration inside a loop, causing the variable to retain its value across iterations instead of being reset each time.
- related: https://github.com/biomejs/biome/issues/6003
  Same rule (noUselessUndefinedInitialization) but different context (Svelte file) and likely different cause.
- related: https://github.com/biomejs/biome/issues/6906
  Same rule (noUselessUndefinedInitialization) but different construct (function with union return types).
- related: https://github.com/biomejs/biome/pull/8776
  Same rule (noUselessUndefinedInitialization) fix for Svelte false positive, different construct.
- related: https://github.com/biomejs/biome/issues/2533
  Original implementation issue for the same rule (noUselessUndefinedInitialization).

<details><summary>All hits</summary>

- [github, open] 💅 `noUselessUndefinedInitialization` safe fix removes a `var` reset inside loops and redeclarations — https://github.com/biomejs/biome/issues/11938
- [github, open] 💅 noDuplicateTestHooks: false positive on a local function named `before` called twice in a test — https://github.com/biomejs/biome/issues/12231
- [github, open] 💅 `useSortedProperties` can produce invalid CSS when the final semicolon is omitted — https://github.com/biomejs/biome/issues/12417
- [github, open] 💅 `useSortedProperties` moves Sass variable declarations below their uses — https://github.com/biomejs/biome/issues/12414
- [github, open] 💅 `useSortedProperties` can change behavior when reordering nested CSS rules — https://github.com/biomejs/biome/issues/12413
- [github, open] 💅 `noUnnecessaryConditions`: false positive on an overloaded call with `undefined` as the default argument (Vue `inject`) — https://github.com/biomejs/biome/issues/12040
- [github, open] 💅 `noSkippedTests` conditionally skip fix suggestion — https://github.com/biomejs/biome/issues/9295
- [github, open] 💅 Actually used private method considered unused — https://github.com/biomejs/biome/issues/8185
- [github, open] 💅 cannot detect that the StrictMode component of React is being exported. — https://github.com/biomejs/biome/issues/10609
- [github, open] 💅 noUnnecessaryConditions callback overload false positive — https://github.com/biomejs/biome/issues/11439
- [tavily] 🐛 `--fix` flag ignores `--diagnostic-level` · Issue #7772 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7772
- [tavily] 💅 `noUselessUndefinedInitialization` false positive in svelte 4 file. · Issue #6003 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6003
- [tavily] 💅 lint/nursery/noUselessUndefined fix is unsafe for functions with union return types · Issue #6906 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6906
- [tavily] 💅 `useSimplifiedLogicExpression` "safe" fix breaks code · Issue #11351 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/11351
- [github, open] 💅 `lint/correctness/noUnusedImports` does not consider uses inside comments that precede non-declaration statements (start/end of file, etc.) — https://github.com/biomejs/biome/issues/8762
- [github, closed] 💅 useReactCompiler silently skips any file that contains an inline `export type` / `export interface` declaration — https://github.com/biomejs/biome/issues/12320
- [github, open] 💅 When using useNamingConvention, prefix and suffix functionality cannot be used in destructuring assignment renaming. — https://github.com/biomejs/biome/issues/8953
- [github, closed] 💅 lint/correctness/useExhaustiveDependencies does not consider global variables as necessary dependencies  — https://github.com/biomejs/biome/issues/8885
- [github, closed] 💅 False error (or at least a misleading one) - private class member never used — https://github.com/biomejs/biome/issues/6933
- [github, closed] 💅 `noInvalidUseBeforeDeclaration` false positive — https://github.com/biomejs/biome/issues/6719
- [tavily] fix(linter): noUselessUndefinedInitialization false positive in svelte 4. by codiini · Pull Request #8776 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/8776
- [tavily] 📝 Sorting tailwind class with a calc is broken · Issue #5496 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5496
- [tavily] 💅 Biome not skipping excluded, generated, file in Monorepo configuration · Issue #7372 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7372
- [tavily] 💅 False positive `lint/nursery/noUnknownPseudoElement` with `::view-transition-new(<pt-name-selector>)` · Issue #5998 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5998
- [tavily] 📎 Implement `noUselessUndefinedInitialization` - `eslint/no-undef-init` · Issue #2533 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/2533
- [tavily] 📝 Biome does not respect license headers when sorting imports · Issue #4210 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/4210
- [tavily] fix(lint): handle namespace declaration merging in noUnusedVariables by taberoajorge · Pull Request #9320 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/9320
- [tavily] 💅 useReactCompiler confused by writing to variable in useEffect · Issue #11671 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/11671
- [tavily] 💅noDelete suggest assigning undefined instead of delete for process.env vars · Issue #4093 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/4093
- [tavily] 💅 useOptionalChain causes crashes when applied to global variables · Issue #7517 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7517
- [tavily] 🐛 Detected case of unusually large amount of types · Issue #8204 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8204
- [tavily] 📎 Implement `noUnnecessaryConditions` · Issue #6611 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6611
- [tavily] 💅 noUnnecessaryConditions: new RegExp(...).exec() is treated as non-nullable · Issue #11278 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/11278

</details>
