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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
deleteis 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.