prop equals undefined vs prop in when prop doesn't exist

JavaScript performance comparison

Test case created

Info

Compares obj[propName] != undefined (yes, loose) to propName in obj. Yes, these are not the same. This is the test for when the prop does not exist.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    // Use something that has more than one prototype
    // in its prototype chain
    var obj = new Date();
    obj.existant = "yes";
};
</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
equals
if (obj['nonexistant'] != undefined) throw "Error";
pending…
in
if ('nonexistant' in obj) throw "Error";
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