Javascript clears a variable after there is no further reference it
Posted
by
Praveen Prasad
on Stack Overflow
See other posts from Stack Overflow
or by Praveen Prasad
Published on 2011-03-02T15:16:22Z
Indexed on
2011/03/02
15:25 UTC
Read the original article
Hit count: 300
JavaScript
|javascript-performance
It is said, javascript clears a variable from memory after its being referenced last.
just for the sake of this question i created a JS file with only one variable;
//file start
//variable defined
var a=["Hello"]
//refenence to that variable
alert(a[0]);
//
//file end
no further reference to that variable, so i expect javascript to clear varaible 'a'
Now i just ran this page and then opened firebug and ran this code
alert(a[0]);
Now this alerts the value of variable, If the statement "Javascript clears a variable after there is no further reference it" is true how come alert() shows its value.
Is it because all variable defined in global context become properties of window object, and since even after the execution file window objects exist so does it properties.
© Stack Overflow or respective owner