Improving hasOwnProperty

JavaScript performance comparison

Revision 8 of this test case created by 51L3N7

Preparation code

<script>
  var obj = {
    foo: 'bar',
    a: 'b',
    c: 'd',
    e: 'f'
  };
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Use hasOwnProperty
obj.hasOwnProperty('foo');
obj.hasOwnProperty('notthere');
pending…
Use void 0
obj['foo'] !== void 0;
obj['notthere'] !== void 0;
pending…
Use undefined
typeof obj['foo'] !== 'undefined';
typeof obj['notthere'] !== 'undefined';
pending…
Use in
'foo' in obj;
'notthere' in obj;
pending…
Use void, dot notation
obj.foo !== void 0;
obj.notthere !== void 0;
pending…
Use void, dot notation, typeof
typeof obj.foo !== void 0;
typeof obj.notthere !== void 0;
pending…
Use void, array, typeof
typeof obj['foo'] !== void 0;
typeof obj['notthere'] !== void 0;
pending…
Double bang
!!obj['foo']
!!obj['notthere']
pending…
Double bang 2
!!obj.foo;
!!obj.notthere;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment