Is it possible to delete a variable declared using const?

后端 未结 1 1999
轻奢々
轻奢々 2020-11-28 15:14

Given

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

Is it possible to delete a vari

相关标签:
1条回答
  • 2020-11-28 15:55

    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?

    0 讨论(0)
提交回复
热议问题