Given
const localName = "local_name"; delete localName; // true console.log(localName); // "local_name"
Is it possible to delete a variable declared using const?
const
delete is used to delete properties from an object.
delete
delete foo;
will try to delete the property foo from the global object. Declared variables can never be removed with delete (no matter if you use const, let or var), and there is no other way to remove a "variable" (binding) (see @T.J.'s comment for some more details).
foo
let
var
Related: How to unset a JavaScript variable?
1.4m articles
1.4m replys
5 comments
57.0k users