Skip to main content

js/noDeleteVars

disallow deleting variables

ESLint Equivalent: no-delete-var

Examples

Invalid

const foo = 'test';
delete foo;

 file.js:2 lint/js/noDeleteVars ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  This is an invalid use of the delete operator.

    1const foo = 'test';
  > 2delete foo;
     ^^^^^^^^^^

  Only object properties can be deleted.

Valid

const arr = [['a','b','c'], [1, 2, 3]];
delete arr[0][2];
const obj = {a: {b: {c: 123}}};
delete obj.a.b.c;
const foo = new Set([1,2,3]);
foo.delete(1);