title: In Javascript, why does array.map(String) return array of strings?
body: <p>The list processing routine <code>map</code> on an array object is very convenient at times. Here's one of the handy ways to use it:</p>
  
  <pre><code>var numarr = [1,2,3,4];
  console.log(numarr.map(String))
  
  &gt;&gt;&gt; ["1", "2", "3", "4"]
  </code></pre>
  
  <p>I took this for granted thus far. Today I was however puzzled by it. What the <code>map</code> function is returning above is an array of strings. We typically pass a function to <code>map</code> as argument. In above case we pass <code>String</code> object. <code>String</code> is implemented inside the Javascript implementation, so I don't know what kind of specialities it has. The above code works as if a <code>new</code> instance of <code>String</code> is created for each item in array.</p>
  
  <p>If it's not clear, consider this. If I decide to implement an object in Javascript say <code>MyString</code> and pass it to <code>map</code>, I won't get the above behavior.</p>
  
  <pre><code>function MyString(x) { this.val = x; }
  
  MyString.prototype.toString = function () { return String(this.val); };
  
  var ms = new MyString(4)
  
  console.log(String(ms));
  &gt;&gt;&gt; "4"
  
  var arr = [1,2,3];
  arr.map(MyString)
  &gt;&gt;&gt; [undefined, undefined, undefined]
  </code></pre>
  
  <p>Does anyone know why then arr.map(String) works the way it does?</p>
  
  <p>Update: <a href="https://stackoverflow.com/questions/16329393/in-javascript-why-does-array-mapstring-return-array-of-strings#comment23403334_16329420">A comment I added below</a> clarifies my question better. </p>