Object detection (v6)

Revision 6 of this benchmark created on


Description

http://stackoverflow.com/questions/7174748/javascript-object-detection-dot-syntax-versus-in-keyword/7174775#7174775

Preparation HTML

<script>
  var object = {
    property: 0
  };

  function has(obj, prop) {
    return Object.prototype.hasOwnProperty.call(obj, prop);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
if(object.property)
if (object.property) {

}
ready
if('property' in object)
if ('property' in object) {

}
ready
if(object.hasOwnProperty('property'))
if (object.hasOwnProperty('property')) {

}
ready
if(has(object, 'property'))
if (has(object, 'property')) {

}
ready
using typeof
if (typeof object.property !== 'undefined') {

}
ready
using undefined directly
if (object.property !== undefined) {
}
ready

Revisions

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