arguments.length vs. typeof param === 'undefined'

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function checkLength(a) {
      return !arguments.length;
    }
   
    function checkLength2(a) {
      return arguments.length === 0;
    }
    function checkType(a) {
      return typeof a === 'undefined'
    }
    function checkValue(a) {
      return a === void 0;
    }
   
    function checkValue2(a) {
      return a === undefined;
    }
};
</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
arguments.length
window.result = checkLength('a');
pending…
length2
window.result = checkLength2('a');
pending…
type
window.result = checkType('a');
pending…
value
window.result = checkValue('a');
pending…
value2
window.result = checkValue2('a');
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