typeof function vs instanceof vs toString (v4)

Revision 4 of this benchmark created on


Description

This testcase compares the performance when checking if a variable (argument) is a function. typeof foo === 'function' vs. foo instanceof Function vs toString.call(foo) == "[object Function]".

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
(function() {
 if (typeof foo === 'function') {}
}());
ready
instanceof
(function() {
 if (foo instanceof Function) {}
}());
ready
typeof with ==
(function() {
 if (typeof foo == 'function') {}
}());
ready
toString
(function() {
 if (toString.call(foo) == '[object Function]') {}
}());
ready

Revisions

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