In the following code:
function t(){
var d = new Date (string)
var t = d.getTime();
...
delete (d); //IS THIS IMPLCITE by the scope rules of js ???
That depends on what you expect it to do.
It actually does nothing in this case (if you check, it evaluates to false,
which represents the delete failing).
The "delete" operator in Javascript deletes bindings, not objects. You are
trying to delete the "d" variable itself, not the Date object that it refers
to, but variables declared using "var" can't be deleted so nothing happens.
Fundamentally a no-op, so definitly redundant.
If you want to delete the Date object, all you need to do is to stop
having a reference to it. In this case, the only reference to the Date
object is the "d" variable, and it will stop existing when the function
call that declared it ends. I.e., when the function returns, the Date
object is no longer available, and it will eventually be garbage collected.
If you wanted the Date object to be garbage collectable earlier than
that (more likely in a case where you have a variable referencing a
much larger object, and you are doing a lot of work before returning
from the function), you can overwrite the reference by assigning a new
value to "d", e.g., "d = null;". If d held the only reference to the
object, then the object can no longer be accessed after the assignment,
and the garbag collector may collect it at will.
In this sense, JavaScript is a arbage collected language like Java,
which also has "new", but not "delete".
/L