hasOwnProperty vs. in (v2)

Revision 2 of this benchmark created on


Description

Compare hasOwnProperty to in check

Preparation HTML

<script>
  var iter = 100,
      testObj = {};
  
  for (var i = 0; i < iter; i++) {
   testObj["foo" + i] = i;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
testObj.hasOwnProperty("foo50");
ready
in check
"foo50" in testObj;
ready
property access
!!testObj["foo50"]
ready
property access type test
typeof testObj["foo50"] !== 'undefined'
ready
property access type test 2
testObj["foo50"] !== undefined
ready
property access miss
!!testObj["foo200"]
ready
property access type test 2 miss
testObj["foo200"] !== undefined
ready

Revisions

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