title: Javascript string stored on stack
body: <p>I'm reading <a href="https://rads.stackoverflow.com/amzn/click/com/1118026691" rel="noreferrer" rel="nofollow noreferrer">Professional JavaScript for Web Developers 3rd ed.</a> and in the summary of chapter 4 one can read:</p>
  
  <blockquote>
    <p>Two types of values can be stored in JavaScript variables: primitive values and reference values.
    Primitive values have one of the five primitive data types: Undefined, Null, Boolean, Number, and String. Primitive and reference values have the following characteristics:</p>
    
    <ul>
    <li>Primitive values are of a fixed size and so are stored in memory on the stack.</li>
    </ul>
  </blockquote>
  
  <p>But I can have different strings, say:</p>
  
  <blockquote>
    <p>var a = "ABC";</p>
    
    <p>// or</p>
    
    <p>var b = "Some very irritatingly long string..."</p>
  </blockquote>
  
  <p>They clearly differ in size, so how can they be allocated on the stack?</p>
  
  <p>I believe the same question can be asked about numbers...</p>
  
  <p>So I am for sure missing something important here.</p>
  
  <p>Can someone explain why strings/numbers are of fixed size and how they can be stored on stack?</p>