Given
const localName = "local_name";
delete localName; // true
console.log(localName); // "local_name"
Is it possible to delete a variable declared using const
?
Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration).
The delete operator removes a property from an object. It cannot delete a variable. Any property declared with var cannot be deleted from the global scope or from a function's scope.
In the Go To Special dialog box, select the Constants option and then select Numbers. Click OK. Now only nonformula numeric cells are selected. Press Delete to delete the values.
The property of a const object can be change but it cannot be change to reference to the new object.
delete
is used to delete properties from an object.
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).
Related: How to unset a JavaScript variable?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With