Reputation: 3377
10 var x = 5;
11 x = 10;
Does the memory location of the variable x
change in line 11 from line 10 OR does the JavaScript engine just overwrites the memory space originally allocated to x
in line 10 and place the value 10
there? Is this specified, or engine-dependent?
Upvotes: 0
Views: 173
Reputation: 960
According to Javascript documentation, assigning values means reading and writing to memory that is already allocated.
When you assign a variable, memory is allocated. When you change its value, reading and writing is done on the same memory location.
Upvotes: 1