PDA

View Full Version : Deleting Variables?



???
06-17-2007, 04:33 PM
I think this will be my last thread for a while. Can you delete variables? Like with:

var blah = "hi";
delete blah;

Or something like that? Because otherwise with a complex enough script they could pile up, unless you used one array for every var.

mwinter
06-17-2007, 04:54 PM
I think this will be my last thread for a while. Can you delete variables?

Properties can be deleted, at least on user-defined native objects. Properties of host objects (such as DOM objects) and most built-in properties cannot usually be deleted. Try to do so can lead to exceptions in IE (though that's a mistake, in my opinion: the operator should just return false).

Variables - properties defined using a var declaration - cannot be deleted.



Because otherwise with a complex enough script they could pile up, ...

Yes, they do, though that not usually a problem. Whenever a document is unloaded, script-defined data is discarded.