typofinifstatment

JavaScript performance comparison

Test case created by Matt Gordon

Info

Checking to see which is more performant, to check the typeof an undefined object or to check the if the null valued variable is false in a conditional.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function myConditional() {
    var myVar;
    if(!myVar){
    return true;
    }
    }
   
    function myConditionalUndefined() {
    var myVar;
    if(typeof myVar === 'undefined'){
    return true;
    }
    }
};
</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
undefinedCheck
myConditionalUndefined();
pending…
isFalseCheck
myConditional();
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