Why is 4 not an instance of Number?
<p>Just curious: </p>

<ul>
<li>4 instanceof Number => false</li>
<li>new Number(4) instanceof Number => true?</li>
</ul>

<p>Why is this? Same with strings: </p>

<ul>
<li><code>'some string' instanceof String</code> returns false</li>
<li><code>new String('some string') instanceof String</code> => true</li>
<li><code>String('some string') instanceof String</code> also returns false</li>
<li><code>('some string').toString instanceof String</code> also returns false</li>
</ul>

<p>For object, array or function types the instanceof operator works as expected. I just don't know how to understand this.</p>

<p>[re-opened to share new insights]</p>

<p>After testing I cooked up this functionality to be able to retrieve the type of <em>any javascript object</em> (be it primitive or not):</p>

<pre><code>Object.prototype.typof = objType;    
objType.toString = function(){return 'use [obj].typof()';};
function objType() {
      var inp = String(this.constructor),
          chkType = arguments[0] || null,
          val;
      function getT() {
         return (inp.split(/\({1}/))[0].replace(/^\n/,'').substr(9);
      }
      return chkType
           ? getT().toLowerCase() === chkType.toLowerCase()
           : getT();
}
</code></pre>

<p>Now you can check any type like this:</p>

<pre><code>var Newclass = function(){}; //empty Constructor function
(5).typof(); //=&gt; Number
'hello world'.typof(); //=&gt; String
new Newclass().typof(); //=&gt; Newclass
</code></pre>

<p>Or test if an object is of some type:</p>

<pre><code>(5).typof('String'); //=&gt; false
new Newclass().typof('Newclass') //=&gt; true
[].typof('Arrray'); //=&gt; true;
</code></pre>
