hasOwnProperty vs in vs undefined (v40)

Revision 40 of this benchmark created on


Setup

var obj = {
      actions: true
    };
    var __hasProp = Object.prototype.hasOwnProperty;
    localStorage.setItem('actions', 'true');

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
is undefined
if (typeof obj.test === 'undefined') {
  return false;
}
ready
localStorage true
if (localStorage.getItem('actions') === 'true') {
  return true;
}
ready
localStorage3
if (localStorage.getItem('actions') === 'true' && obj["actions"] !== undefined) {
  return false;
}
ready

Revisions

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