biome complexity/noUselessUndefinedInitialization: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
In a comma-separated declaration like `var a = undefined, b = 1;`, removing `= undefined` results in `var a, b = 1;`, which is valid and equivalent because `a` is still implicitly `undefined`.
Program
Output
After redeclaration: undefined number
After redeclaration: assigned number
- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory real · high
The fix removes the explicit `= undefined` initializer from a `var` declaration inside a block, but `var` is function-scoped and hoisted. The original code re-initialized the function-scoped `a` to `undefined` when the block executed, overwriting the earlier assignment `a = 'assigned'`. After the fix, the declaration becomes `var a` with no initializer, which does not re-assign `a` at runtime, so the outer assignment persists and the program prints `assigned` instead of `undefined`. The documentation presents the rewrite as equivalent, but for function-scoped `var` the initializer has observable runtime effect, making the fix unsafe for this construct.
Explanation Nemotron 3 Super unverified
The original declaration `var a = undefined` initializes variable `a` to `undefined`, overriding its prior value `'assigned'` due to hoisting within the same scope. Removing `= undefined` leaves `a` uninitialized initially but still redeclared via `var`, so it retains the outer assignment’s value `'assigned'`. Thus `console.log` outputs different values for `a`. This change alters observable behavior, violating semantic preservation.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p007.js
- evidence sheet
- r1-p007.md
- regression fixture
- r1-p007.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js bunx @biomejs/biome lint --only=complexity/noUselessUndefinedInitialization --write prog.js node prog.js
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
noUselessUndefinedInitialization fix · complexity noUselessUndefinedInitialization variable declaration · var initialization redundant undefined assignment · block-scoped variable shadowing outer scope
- duplicate biomejs/biome/issues/11938 same rule removing = undefined from a var redeclaration inside a block, which resets the outer variable
- related biomejs/biome/issues/6003 same rule but in Svelte files, not plain JS var redeclaration
- related biomejs/biome/issues/6906 same rule but about function return types, not var redeclaration
- related biomejs/biome/pull/8776 same rule fix for Svelte false positive, not var redeclaration
- related biomejs/biome/issues/2533 original implementation issue for the same rule, not this specific defect
Details
- program
- Comma-Separated Declaration Equivalence
- hazard
- In a comma-separated declaration like `var a = undefined, b = 1;`, removing `= undefined` results in `var a, b = 1;`, which is valid and equivalent because `a` is still implicitly `undefined`.
- oracle
stdout before: After redeclaration: undefined number stdout after: After redeclaration: assigned number- run
- 2026-10-17T20-10-15-247Z-vb8k-biome-complexity_noUselessUndefinedInitialization
generated program (15 lines) and the fix's diff
--- orig.js 2026-10-17 16:10:29.950350814 -0400 +++ fixed.js 2026-10-17 16:10:30.215343061 -0400 @@ -1,12 +1,12 @@ function commaTest() { - var a = undefined, b = 1; // Rule triggers on a + var a , b = 1; // Rule triggers on a console.log('Initial:', typeof a, b); a = 'assigned'; console.log('After reassignment:', a, b); // Re-enter scope to test re-declaration if (true) { - var a = undefined, c = 2; // Rule triggers again + var a , c = 2; // Rule triggers again console.log('Redecled:', a, c); } console.log('After redeclaration:', a, typeof c);
rule documentation given to the models
Summary
- Name: noUselessUndefinedInitialization
- Fix: safe
- Default severity: info
- Available from version: 1.7.2
- Diagnostic category: lint/complexity/noUselessUndefinedInitialization
- This rule is recommended
Description
Disallow initializing variables to `undefined`.
A variable that is declared and not initialized to any value automatically gets the value of `undefined`.
It’s considered a best practice to avoid initializing variables to `undefined`.
Please note that any inline comments attached to the initialization value or variable will be moved at the end of the variable declaration on auto-fix.
Please be also aware that this differs from Eslint's behaviour.
Examples
Invalid
```js,expect_diagnostic
var a = undefined;
```
```js,expect_diagnostic
let b = undefined, c = 1, d = 2;
```
```js,expect_diagnostic
for (let i = 0; i < 100; i++) {
let i = undefined;
}
```
```js,expect_diagnostic
let f = /**/undefined/**/ ;
```
Valid
```js
var a = 1;
```
```js
class Foo {
bar = undefined;
}
```
Exported variables are not flagged because in some frameworks (e.g., Svelte 4),
initializing exported variables to `undefined` is used to declare optional props.
```js
export let x = undefined;
```
```js
let y = undefined;
export { y };
```