hasOwnProperty vs in vs undefined (v42)

Revision 42 of this benchmark created on


Description

A variant of http://jsperf.com/hasownproperty-vs-in-vs-undefined/12 just without the "var undefined" in the test code. This changes the picture for all the "undefined" dependent tests.

Setup

var Iobj = {
      SUPPORT_ACTIONS: 0x1
    };
    var obj = {
      actions: true,
      support: Iobj.SUPPORT_ACTIONS
    };
    
    var has = function(obj, prop) { //instead of has.call(obj, prop)
       return typeof obj[prop] !== "undefined";
    };
    
    var _has = Object.hasOwnProperty;

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
if (obj.hasOwnProperty("actions")) {
  return true;
}
ready
in
if ("actions" in obj) {
  return true;
}
ready
is undefined
if (has(obj, "actions")) {
  return true;
}
ready
!== undefined
if (obj['actions'] !== undefined) {
  return true;
}
ready
typeof !== 'undefined'
if (typeof obj['actions'] !== 'undefined') {
  return true;
}
ready
hasOwnProperty.call
_has.call(obj, "actions");
ready

Revisions

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