no-undef-init

Disallow initializing a variable to undefined

fixable

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.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"no-undef-init" = "error" # or "warn"

Examples#

example.js1 problem
let selected = undefined;
example.jsNo problems
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.