hasOwnProperty vs in vs undefined (v2)

Revision 2 of this benchmark created on


Setup

var obj = {
       actions : ['foo', 'foo2', 'bar']
    };
    var undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
if (obj.actions.hasOwnProperty("foo")) {
      return true;
}
ready
in
if ("foo" in obj.actions) {
      return true;
}
ready
undefined
if (typeof obj.actions.foo !== 'undefined') {
      return true;
}
ready
undefined cmp
if (obj.actions.foo !== undefined) {
      return true;
}
ready

Revisions

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