hasOwnProperty vs in vs undefined (v25)

Revision 25 of this benchmark created on


Setup

var Iobj = {
      SUPPORT_ACTIONS: 0x1
    };
    var obj = {
      //actions: 'action1 action2 action3',
      support: Iobj.SUPPORT_ACTIONS
    };
    
    var hasOwn = Object.prototype.hasOwnProperty;

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
return obj.hasOwnProperty("actions");
ready
in
return "actions" in obj;
ready
undefined
return typeof obj.actions !== 'undefined';
ready
undefined cmp
return obj.actions !== undefined;
ready
binary indicator
return (obj.support & Iobj.SUPPORT_ACTIONS) !== 0;
ready
undefined cmp (dynamic)
return obj['actions'] !== undefined;
ready
undefined dynamic
return typeof obj['actions'] !== 'undefined';
ready
hasOwnProperty prototype
return Object.prototype.hasOwnProperty.call(obj, "actions");
ready
hasOwnProperty var saved
return hasOwn.call(obj, "actions");
ready
Truthy
return !!obj['actions'];
ready
not void 0
return obj['actions'] !== void 0;
ready

Revisions

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