title: Are primitive / reference types stored on the heap or on the stack?
body: <p>What determines the storage type in JS? Does it have anything to do with the primitive vs reference types?</p>
  
  <p>I'm coming from the C++ / python background. Reading the answers and comments to <a href="https://stackoverflow.com/questions/13266616/primitive-value-vs-reference-value">this question</a>, I have encountered a few mutually incompatible (and even internally inconsistent) statements:</p>
  
  <p>From the <a href="https://stackoverflow.com/a/13266769/336527">accepted answer</a>:</p>
  
  <blockquote>
    <ul>
    <li><code>Primitive values</code> are data that are stored on the <strong>stack</strong>.</li>
    <li><code>Primitive value</code> is stored directly in the location that the variable accesses.</li>
    <li><code>Reference values</code> are <strong>objects</strong> that are stored in the <strong>heap</strong>.</li>
    <li><code>Reference value</code> stored in the variable location is a pointer to a location in memory where the object is stored.</li>
    </ul>
  </blockquote>
  
  <p>From the <a href="https://stackoverflow.com/questions/13266616/primitive-value-vs-reference-value#comment75759398_13266769">comment</a> on it:</p>
  
  <blockquote>
    <p>Whether values are stored on the stack or heap is not determined by their type in JS. It depends on the lifetime of the variable it is stored in (affected by scopes and especially closures, and depending upon the analytical capabilities of the engine).</p>
  </blockquote>
  
  <p>From the highest voted answer:</p>
  
  <blockquote>
    <p>JavaScript doesn't have a stack or a heap. It's a dynamic language and all the variables in JavaScript are dynamic. [...] All the values (primitives and objects) in JavaScript are allocated from the heap. Even the variables themselves are allocated from the heap.</p>
  </blockquote>
  
  <p>Could someone please clarify or refer me to a technically correct explanation? If the approach is implementation-dependent, I'd appreciate references to the differences in implementation.</p>