Improving hasOwnProperty

JavaScript performance comparison

Test case created by Shane O'Sullivan

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
obj['foo'] !== undefined;
obj['notthere'] !== undefined;
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