hasOwnProperty vs in vs undefined (v15)

Revision 15 of this benchmark created on


Setup

var Iobj = {
      SUPPORT_ACTIONS: 0x1
    };
    var obj = {
      actions: true,
      support: Iobj.SUPPORT_ACTIONS
    };
    var undefined;

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
undefined
if (typeof obj.actions !== 'undefined') {
  return true;
}
ready
undefined cmp
if (obj.actions !== undefined) {
  return true;
}
ready
binary indicator
if (obj.support & Iobj.SUPPORT_ACTIONS) return true;
ready
undefined cmp (dynamic)
if (obj['actions'] !== undefined) {
  return true;
}
ready
undefined dynamic
if (typeof obj['actions'] !== 'undefined') {
  return true;
}
ready
hhasOwnProperty prototype
if (Object.prototype.hasOwnProperty.call(obj, "actions")) {
  return true;
}
ready
hasOwnProperty('actions') & return
if (obj.hasOwnProperty("actions")) {
  return obj['actions'];
}
ready
['actions'] & return
if (obj['actions']) {
  return obj['actions'];
}
ready
for in & return
if ('actions' in obj) {
  return obj['actions'];
}
ready
typeof & return
if (typeof obj['actions'] !== 'undefined') {
  return obj['actions'];
}
ready

Revisions

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