title: what is the best way to check variable type in javascript
body: <pre><code>&lt;script type="text/javascript"&gt;   
  function saveName (firstName) {
      function capitalizeName () {
          return firstName.toUpperCase();
      }
      var capitalized = capitalizeName();console.log(capitalized instanceof String);
      return capitalized; 
  }
  console.log(saveName("Robert")); // Returns "ROBERT"
  &lt;/script&gt;
  </code></pre>
  
  <p>Question:</p>
  
  <p>I want to check the type of capitalized , so I use <code>capitalized instanceof String</code>? But it shows: <code>false</code> in console, I do not want to try <code>capitalized instanceof Function</code>, <code>Object</code>...It will take too much time, so what is the best way to detect a variable type?</p>