Relationship of variables and memory in Javascript