I've been studying JavaScript language itself, and came up with a question. What does it look like when assinging a variable with primitive value to other variable?
For example, take a look at the code below, and this is what I think happens:
var num = 30;
var newNum = num;
num = 50;
newNum = 50;
Step by step, I believe that in case of primitive values:
Before actually running JavaScript code:
undefined Once JavaScript runs:
30 to location where its identification is numnewNum50num from existing memory to new memory space allocated from #3,50newNum from existing memory to new memory space allocated from #5So far, this is my understanding of how JavaScript allocates its primitive values with var declaration.
However, I've found some describes differently. They say, both variables num and newNum would point to a same memory space where primitive value 30 is located at. Then, once reassignment happens, they would each detach and point to new memory space where primitive value 50 is located at.