hasOwnProperty vs in vs undefined (v3)

Revision 3 of this benchmark created on


Setup

var obj = {
      actions: ['foo', 'foo2', 'bar'],
      support: 0x1
    };
    var obj_support = {
      action: 0x1
    };
    var undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
if (obj.actions.hasOwnProperty("foo")) {
  return true;
}
ready
in
if ("foo" in obj.actions) {
  return true;
}
ready
undefined
if (typeof obj.actions.foo !== 'undefined') {
  return true;
}
ready
binary indicator
if (obj.support & obj_support.action) {
  return true;
}
ready

Revisions

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