# Stack and Heap Memory

Stack memory is the space allocated for a process where all the function calls, primitive data types (int, double, string...)

VS

Heap memory is used to store the objects that are created during the execution of a program.

Thanks for concepts about reference vs primitives type and heap/stack too!
3:39 string is primitive (copy by value)
6:47 object ,array are references type
7:05 primitives are store on stack
7:35 references are store on heap (take longer to access, store bigger amount of data)
8:40 stack (store like stack 'push on top')
9:16 heap (store pointer)
10:48 it assign a pointer not value
14:50 Object.assign create new object and merge with existing one
16:07 Object.assign doesn't deep clone
17:26 may use Lodash to clone instead
19:04 copy array

![Screenshot (264).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658321615434/AmPLFLJlF.png align="left")


![Screenshot (263).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658321155873/vwW5WlzU7.png align="left")


![img_5b73d7f592aa2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658321173498/qf0xpav6D.png align="left")


![main-qimg-1a1dbbe8b343484a55f3ff386b9cb48a-pjlq.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1658321181691/AXpVOmCEy.jpg align="left")



![1_OGHcuzHaFL8Rz7gL17PriQ.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658321195549/svMyS6gAx.png align="left")


![Screenshot (272).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658394239026/YcSJA3rK3.png align="left")



Element (object) is created in the heap which store the actuall object, 
But we do have a pointer on the stack which stores the reference ,the address to this object in the heap and the variable simply store the pointer.
The varaible doesn't know the address of the place in memory where our object is stored but the variable knows where the pointer lies 
on the stack it knows the position of the pointer on the stack
an the pointer in turn simply stores the address of the object in the heap. 



![Screenshot (274).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658394533275/sJT301QTX.png align="left")


![Screenshot (275).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658394747904/V4lozIp4k.png align="left")

