hasOwnProperty vs in vs undefined (v35)

Revision 35 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.min.js"></script>

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
angular.isDefined
if (angular.isDefined(obj.test)) {
  return false;
}
ready

Revisions

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