title: What is the difference between string primitives and String objects in JavaScript?
body: <p>Taken from <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String?redirectlocale=en-US&amp;redirectslug=JavaScript/Reference/Global_Objects/String#Description" rel="noreferrer">MDN</a></p>
  
  <blockquote>
    <p>String literals (denoted by double or single quotes) and strings
    returned from String calls in a non-constructor context (i.e., without
    using the new keyword) are primitive strings. JavaScript automatically
    converts primitives to String objects, so that it's possible to use
    String object methods for primitive strings. In contexts where a
    method is to be invoked on a primitive string or a property lookup
    occurs, JavaScript will automatically wrap the string primitive and
    call the method or perform the property lookup.</p>
  </blockquote>
  
  <p>So, I thought (logically) operations (method calls) on string primitives should be slower than operations on string Objects because any string primitive is converted to string Object (extra work) before the <code>method</code> being applied on the string.</p>
  
  <p>But in this <a href="http://jsperf.com/heera-string-literal-vs-object" rel="noreferrer">test case</a>, the result is opposite. The <strong>code block-1</strong> runs faster than the <strong>code block-2</strong>, both code blocks are given below:</p>
  
  <p><strong>code block-1 :</strong></p>
  
  <pre><code>var s = '0123456789';
  for (var i = 0; i &lt; s.length; i++) {
    s.charAt(i);
  }
  </code></pre>
  
  <p><strong>code block-2 :</strong></p>
  
  <pre><code>var s = new String('0123456789');
  for (var i = 0; i &lt; s.length; i++) {
      s.charAt(i);
  }
  </code></pre>
  
  <p>The results varies in browsers but the <strong>code block-1</strong> is always faster. Can anyone please explain this, why the <strong>code block-1</strong> is faster than <strong>code block-2</strong>.</p>