no-unassigned-vars
Disallow let and var variables that are read but never assigned
warn by default
A let or var that's declared without a value and never assigned is undefined everywhere you read it. Usually someone forgot the assignment, or a refactor removed it.
no-unused-vars handles variables that are never read.
This rule is on by default.
Configure#
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"no-unassigned-vars" = "off" # or "error"Examples#
example.js1 problem
let statusstatus is always undefined because it's never assigned.;
if (status === "ready") {
start();
}example.jsNo problems
let status;
if (isReady()) {
status = "ready";
}
if (status === "ready") {
start();
}In TypeScript, declare says that the value comes from somewhere else:
example.tsNo problems
declare let version: string;
console.log(version);