Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

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.

Configure

Off by default. To turn it on:

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

Examples

Reported:

let selected = undefined;

Not reported:

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.