hasOwnProperty vs in vs undefined

Benchmark created on


Setup

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

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

Revisions

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