function exampleFunction(){
var theVariable = "Lol!";
var variable2 = Lol.toLowerCase();
console.log(theVariable);
delete theVariable; //to prevent bugs, I want to ensure that this variable is never used from this point onward.
console.log(theVariable); //This still prints "Lol!", even though I just tried to delete the variable.
}
In JavaScript, is it possible to prevent a variable from being used in a function after a certain point? I've tried declaring a string called theVariable
, and then I tried to delete the variable using delete theVariable
, but console.log(theVariable)
still prints theVariable
's value even after that point.
I tried using delete theVariable
to make theVariable
unusable from that point onward (in order to prevent myself from accidentally using the variable when it is no longer needed), but it doesn't appear to have that effect. Is there any way to work around this limitation?