Property detection

Benchmark created by Thomas Fuchs on


Description

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 HTML

<script>
  var obj = {
    a: 1
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
in operator
if ('a' in obj) {};
if ('b' in obj) {};
ready
boolean value
if (obj.a) {};
if (obj.b) {};
ready
hasOwnProperty
if (obj.hasOwnProperty('a')) {};
if (obj.hasOwnProperty('b')) {};
ready

Revisions

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