I'm a self-learning coder and I'm not good enough so far. Question is:
We know that for non-primitives (i.e. Object), references are in the stack while values are in the heap. How about the nested object? IMO because of the different results of the shallow and deep copy of an multidimensional object, the nested object is just a reference in its parent object stored in the heap. Where are the values of the nested object stored at, another space in the heap? Also in javascript we cannot visit data in the heap directly, how do we manipulate the nested object? stack ref → heap ref → heap val chaining???
I'm a green bird and really confused.
P.S. I've seen at least 2 different definitions of shallow/deep copy:
1. Shallow one copies the reference only while deep one copies reference & value
2. Shallow one makes one-dimensional copy while deep one copies every single dimension
Which is correct?