title: JavaScript primitive types and corresponding objects
body: <p>In JavaScript not every data is an object. There exist a few primitive types, like strings, numbers and Boolean which are not objects. For each of these types there exists a constructor which outputs an object with similar behaviour: <code>Number</code>, <code>String</code> and <code>Boolean</code>. To confuse matters, one actually <strong>can</strong> call methods on primitive types - they will be converted to the corresponding objects during this operation, and then converted back. For instance one can do</p>
  
  <pre><code>var a = 4.1324;
  a.toFixed(1) // Outputs 4.1
  </code></pre>
  
  <p>Yet, if you try to compare primitive types and objects with strict equality, the difference shows up</p>
  
  <pre><code>var a = new Number(4);
  var b = 4;
  a === b; // False!!!
  typeof a; // 'object'
  typeof b; // 'number'
  </code></pre>
  
  <p>Actually of one tries to compare objects, they turn out to be different anyway:</p>
  
  <pre><code>var a = new Number(4);
  var b = new Number(4);
  a === b; // False!!!
  </code></pre>
  
  <p><em>(From a conceptual point of view I sort of understand the distinction. Objects can have additional properties, hence they should not compare to equal unless they are actually the same. So if we want to have <code>4 === 4</code> we need to use a type which is not an object. But this dilemma is faced by any sufficiently dynamic programming language, yet JavaScript is the only one I know where there are two types - one objectful and one not - for numbers or strings.)</em></p>
  
  <blockquote>
    <p>What is the advantage of keeping two separate representations for numbers, strings and Booleans? In what context could one need the distinction between primitive types and objects?</p>
  </blockquote>