Property detection

JavaScript performance comparison

Revision 5 of this test case created by Tom

Info

These test if a property exists in an object. The boolean syntax is often used, but can lead to wrong results (a property with a value of false wouldn't be detected, for example).

Preparation code

<script>
  var obj = {
    a: 1
  };
</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
in operator
if ('a' in obj) {}
if ('b' in obj) {}
pending…
boolean value
if (obj.a) {}
if (obj.b) {}
pending…
hasOwnProperty
if (obj.hasOwnProperty('a')) {}
if (obj.hasOwnProperty('b')) {}
pending…
boolean value 2
if (obj['a']) {}
if (obj['b']) {}
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