Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

javascript - Is it possible to delete a variable declared using const?

Given

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

Is it possible to delete a variable declared using const?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...