prototype vs typeof

Edit on GitHub

Setup

Tests

  • prototype

    function isStringByPrototype (val) {
      return _rt('s') === _rt(val);
    }
    function _rt(val) {
      return Object.prototype.toString.call(val);
    }
    
    isStringByPrototype('abcdefg');
  • typeof

    function isStringByTypeof(val) {
      return typeof val === 'string';
    }
    
    isStringByTypeof('abcdefg');