typeof vs constructor

JavaScript performance comparison

Test case created by

Preparation code

<script>
  var foo = function (){};
  var bar = 123;
  var baz = 'yey!';
  var qux = {};
  
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
typeof
typeof foo == 'function';
typeof foo == 'xxxxxx';
typeof bar == 'number';
typeof bar == 'xxxxxx';
typeof baz == 'string';
typeof baz == 'xxxxxx';
typeof qux == 'object';
typeof qux == 'xxxxxx';
pending…
constructor ==
foo.constructor == Function;
foo.constructor == Error;
bar.constructor == Number;
bar.constructor == Error;
baz.constructor == String;
baz.constructor == Error;
qux.constructor == Object;
qux.constructor == Error;
pending…
constructor ===
foo.constructor === Function;
foo.constructor === Error;
bar.constructor === Number;
bar.constructor === Error;
baz.constructor === String;
baz.constructor === Error;
qux.constructor === Object;
qux.constructor === Error;
pending…
constructor.name
foo.constructor.name === 'Function';
foo.constructor.name === 'Error';
bar.constructor.name === 'Number';
bar.constructor.name === 'Error';
baz.constructor.name === 'String';
baz.constructor.name === 'Error';
qux.constructor.name === 'Object';
qux.constructor.name === 'Error';
pending…

Compare results of other browsers

Revisions

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

0 Comments