set default param with if or ||

Benchmark created on


Preparation HTML

<script>
  function ifAssign(x) { /* assign default value if x has not been passed as arg */
    if (!x) {
      x = {};
    }
  }
  
  function ifAssignEquals(x) { /* assign default value if x has not been passed as arg */
    if (x === undefined) {
      x = {};
    }
  }
  
  function ifAssignTypeof(x) { /* assign default value if x has not been passed as arg */
    if (typeof x === "undefined") {
      x = {};
    }
  }
  
  function orAssign(x) { /* assign default value if x has not been passed as arg */
    var x = x || {};
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
ifAssign
ifAssign()
ready
ifAssignEquals
ifAssignEquals()
ready
ifAssignTypeof
ifAssignTypeof()
ready
orAssign
orAssign()
ready

Revisions

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