Skip to content

no-delete-var

Reports delete applied to a plain variable name, also in parentheses (delete x, delete (x)). delete x.y and delete x[0] remove a property and are not reported.

delete removes object properties, not variables. On a variable it does nothing in sloppy mode (the expression is false) and is a syntax error in strict mode and in modules, so the code either has no effect or does not run.

To fix, assign undefined to the variable or leave the scope, or delete the property of an object instead.

Reported
...
var x; delete x; delete x.y; delete (x);
...
js:
lint:
rules:
no-delete-var: error # off, warn, error (default)

Enabled by the presets: js/eslint-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-delete-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-delete-var full