hasOwnProperty vs in vs undefined (v39)

Revision 39 of this benchmark created by Goktug on


Setup

var obj = {
      ypjlvs: 23,
      odypvr: 3,
      kkflew: 4,
      exgqfq: 15,
      yjxkft: 16,
      enwdhe: 16,
      rjqoyx: 21,
      ahppci: 15,
      rgzdka: 25,
      mpohsu: 25,
      actions: 'action1 action2 action3',
      actions2: 'action1 action2 action3',
      val1: 1,
      val2: 1,
      val3: 1
    }
    
    var createObj = Object.create(null);
    for (var x in Object.keys(obj)) {
      createObj[x] = obj[x];
    }

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
return obj.hasOwnProperty("actions");
ready
in
return "actions" in obj;
ready
undefined
return obj['actions'] !== undefined;
ready
undefined typeof
return typeof obj['actions'] !== 'undefined';
ready
Truthy
return !!obj['actions'];
ready
in createObj
return "actions" in createObj;
ready
undefined createObj
return typeof createObj['actions'] !== 'undefined';
ready
Truthy createObj
return !!createObj['actions'];
ready

Revisions

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