user1902183
user1902183

Reputation: 3377

JavaScript primitives: same memory location, new memory location, or engine-dependent?

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

Answers (1)

Divyanth Jayaraj
Divyanth Jayaraj

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

Related Questions