Capital One Interview Question

Why do we keep variables on the heap in Javascript?

Interview Answer

Anonymous

Mar 22, 2019

This is an odd question since the exact storage of variables is implementation dependent. The spec never mentions the word "heap" once and stack is only used in other contexts. There is an "execution context stack" where function-local variables are stored, but this is not exactly analogous to the traditional stack in an assembly/C programming sense. You can find answers online that say primitives and the references to objects are stored on the stock and all complex objects are stored on the heap, but this is not really guaranteed to be correct across all implementations.