Here’s a super-short summary: The stack is essentially an easy easy-to-access memory that simply manages its items as as a - well - stack stack. Only items for which the size is known in advance can go onto the stackitems for which the size is known in advance can go onto the stack. This is the case for numbers, strings, booleans.
The heap is a memory for items of which you can’t pre-determine the exact size and structureheap is a memory for items of which you can’t predetermine the exact size and structure. Since objects and arrays can be mutated and change at runtime, they have to go into the heap therefore.
Source: Academind