Reputation: 533
I used delete keyword to delete a variable but it doesn't seem to work....
var txt = "Some text";
alert(txt); //Output - Some text
delete txt;
alert(txt); //SAME OUTPUT - Some text
Upvotes: 0
Views: 243
Reputation: 150080
delete
is used to delete properties, not variables. That is, it is used to remove a property from an object.
According to MDN's explanation of delete
, "You can use the delete operator to delete variables declared implicitly but not those declared with the var or the function statement."
So the behaviour you've described is correct.
Upvotes: 1