is string

Benchmark created on


Preparation HTML

<script>
  var string = Object("abc");
  var Object__toString = Object.prototype.toString;
  
  function typeOf(object) {
   var type = typeof object;
  
   switch (type) {
   case "object":
   case "unknown":
    return object == null ? "null" : "valueOf" in object // JS object
    ? "getUTCDay" in object ? "object" : typeof object.valueOf() // underlying type
    : /native code/.test(object) ? "function" : "object";
  
   case "function":
    return "call" in object ? "function" : "object";
  
   default:
    return type;
   }
  };
  
  var object = document.childNodes;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
constructor
var result1 = string.constructor == String;
var result2 = object.constructor == String;
ready
instanceof
var result1 = string instanceof String;
var result2 = object instanceof String;
ready
duck type
var result1 = "toUpperCase" in string;
var result2 = "toUpperCase" in object;
ready
Object::toString
var result1 = Object__toString.call(string) === "[object String]";
var result2 = Object__toString.call(object) === "[object String]";
ready
{}.toString
var result1 = {}.toString.call(string) === "[object String]";
var result2 = {}.toString.call(object) === "[object String]";
ready
valueOf()
var result1 = typeof string.valueOf() == "string";
var result2 = typeof object.valueOf() == "string";
ready
typeof())
var result1 = typeOf(string) == "string";
var result2 = typeOf(object) == "string";
ready
combination
var result1 = "valueOf" in string && typeof string.valueOf() == "string";
var result2 = "valueOf" in object && typeof object.valueOf() == "string";
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.