Well ... a few possible direct answers.
myVar = undefined;
myVar = null;
delete window.myVar;
HOWEVER, I would question the logic of having a global variable, but it can only be used in certain methods. Here, how best to structure (with a random pseudo-example of adding values from ajax):
addAjaxButton.onClick(function() {
var counter = 0;
ajax(function(addition) {
counter += addition;
ajax(function(moreAdd) {
counter += moreAdd;
alert('Total is ' + counter);
});
});
});
In this case, the counter does not need to be deleted - it will just go out of scope when all AJAX is complete.
source
share