defaulting an argument

JavaScript performance comparison

Test case created by stash

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    window.firstForm = function firstForm(someParam) {
      someParam = someParam || 'default';
      return someParam;
    }
   
    window.secondForm = function secondForm(someParam) {
      someParam || (someParam = 'default');
      return someParam;
    }
   
    window.thirdForm = function thirdForm(someParam) {
      if (!someParam) {
        someParam = 'default';
      }
      return someParam;
    }
};
</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
first form, unset
var x = firstForm(null);
pending…
first form, set
var x = firstForm('set');
pending…
second form, unset
var x = secondForm(null);
pending…
second form, set
var x = secondForm('set');
pending…
third form, unset
var x = thirdForm(null);
pending…
third form, set
var x = thirdForm('set');
pending…

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

Compare results of other browsers

0 comments

Add a comment