Object detection (v14)

Revision 14 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(typeof object.property !== 'undefined') {

}
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
bracket
if(object['property']){
}
ready

Revisions

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