Property detection (v13)

Revision 13 of this benchmark created 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
  };
  
  var el = document.createElement('div');
</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
boolean value 2
if (obj['a']) {}
if (obj['b']) {}
ready
in operator (element)
if ('localName' in el) {}
if ('parentNode' in el) {}
ready
boolean value (element)
if (el.localName) {}
if (el.parentNode) {}
ready
hasOwnProperty (element)
if (el.hasOwnProperty('localName')) {}
if (el.hasOwnProperty('parentNode')) {}
ready
boolean value 2 (element)
if (el['localName']) {}
if (el['parentNode']) {}
ready

Revisions

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