Skip to content

no-var

Reports a var declaration (also declare var in TypeScript). let and const are not reported.

A var belongs to the whole function, not to the block, and is hoisted: it can be read before its line (as undefined) and declared twice in one scope without an error. let and const are limited to their block, a second declaration is an error, and const states that the binding does not change.

To fix, use const where the variable is not assigned again, otherwise let.

Reported
var a = 1;
...
let c = 3;
c = 4;
...
js:
lint:
rules:
no-var: warn # off (default), warn, error

Enabled by the presets: js/typescript-eslint-recommended.

Suppress one line with sudsy-disable-next-line no-var in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-var full