Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to delete a variable declared using const?

Tags:

javascript

Given

const localName = "local_name";
delete localName; // true
console.log(localName); // "local_name"

Is it possible to delete a variable declared using const?

like image 813
guest271314 Avatar asked Feb 23 '17 18:02

guest271314


People also ask

Can we change value of 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).

Can we delete using delete operator any property declared with VAR let const from the global scope or from a function's scope?

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.

How do you delete a constant?

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.

Can you modify const?

The property of a const object can be change but it cannot be change to reference to the new object.


1 Answers

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?

like image 171
Felix Kling Avatar answered Oct 24 '22 15:10

Felix Kling