hasOwnProperty vs in vs undefined (v17)

Revision 17 of this benchmark created by Tal on


Setup

var Iobj = {
      SUPPORT_ACTIONS: 0x1
    };
    var obj = {
      actions: 'action1 action2 action3',
      support: Iobj.SUPPORT_ACTIONS
    };
    var biggerObj = {
    ypjlvs:23,odypvr:3,kkflew:4,exgqfq:15,yjxkft:16,enwdhe:16,rjqoyx:21,ahppci:15,rgzdka:25,mpohsu:25, 
      actions: 'action1 action2 action3',
      support: Iobj.SUPPORT_ACTIONS,
      val1: 1,val2:1, val3:1
    }

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 on literal
return {}.hasOwnProperty.call(obj, "actions");
ready
Truthy
return !!obj['actions'];
ready
not void 0
return obj.actions !== void 0;
ready
in bigger
return "actions" in biggerObj;
ready
undefined bigger
return typeof biggerObj.actions !== 'undefined';
ready

Revisions

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