hasOwnProperty vs in vs undefined (v34)

Revision 34 of this benchmark created by Pencroff on


Setup

var obj = {
      actions: true
    };
    var __hasProp = Object.prototype.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
bool (dynamic)
if (obj["actions"]) {
  return true;
}
ready
bool (coherency check)
if (obj.actions) {
  return true;
}
ready
hasOwnProperty (2)
if (obj.hasOwnProperty('test')) {
  return false;
}
ready
in (2)
if ("test" in obj) {
  return false;
}
ready
bool (dynamic) (2)
if (obj["test"]) {
  return false;
}
ready
bool (coherency check) (2)
if (obj.test) {
  return false;
}
ready
hasOwnProperty closure
if(__hasProp.call(obj, "actions")) {
  return true;
}
ready
hasOwnProperty closure(2)
if(__hasProp.call(obj, "test")) {
  return false;
}
ready

Revisions

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