hasOwnProperty vs in vs undefined (v54)

Revision 54 of this benchmark created on


Setup

var obj = {
      actions: {
        x: 1
      }
    };

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 typeof
if (typeof obj.actions !== 'undefined') {
  return true;
}
ready
undefined cmp
if (obj.actions !== undefined) {
  return true;
}
ready
undefined cmp (dynamic)
if (obj['actions'] !== undefined) {
  return true;
}
ready
undefined dynamic
if (typeof obj['actions'] !== 'undefined') {
  return true;
}
ready
undefined implicit
if (obj.actions) {
  return true;
}
ready
undefined implicit 2
if (obj['actions']) {
  return true;
}
ready
void 0
if (obj.actions !== void 0) {
  return true;
}
ready
not null
if (obj.actions != null) {
  return true;
}
ready
not null dynamic
if (obj["actions"] != null) {
  return true;
}
ready

Revisions

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