是否可以删除使用const声明的变量? [英] Is it possible to delete a variable declared using const?
本文介绍了是否可以删除使用const声明的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定
const localName = "local_name";
delete localName; // true
console.log(localName); // "local_name"
是否可以删除使用 const声明的变量
?
推荐答案
删除
用于从对象中删除属性。
delete
is used to delete properties from an object.
delete foo;
将尝试删除属性 foo
全局对象。使用 delete
永远不会删除声明的变量(无论你使用 const
,让
或 var
),没有其他方法可以删除变量(绑定)(请参阅@TJ的评论以获取更多细节) 。
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).
这篇关于是否可以删除使用const声明的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文