typeof function vs instanceof

JavaScript performance comparison

Revision 3 of this test case created by Gildas

Info

This testcase compares the performance when checking if a variable (argument) is a function. typeof foo === 'function' vs. foo instanceof Function.

Preparation code

<script>
  var foo = function() {};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
typeof
(function() {
 if (typeof foo === 'function') {}
}());
pending…
instanceof
(function() {
 if (foo instanceof Function) {}
}());
pending…
typeof with ==
(function() {
 if (typeof foo == 'function') {}
}());
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. Here’s a list of current revisions for this page:

0 comments

Add a comment