Check if object has property (v5)

Revision 5 of this benchmark created on


Description

Comparing use of prop in object vs. typeof object !== 'undefined' vs !(object.property)

Setup

window.checkObjectTestExample = { 'pronic': 42 };

Teardown


    delete window.checkObjectTestExample;
  

Test runner

Ready to run.

Testing in
TestOps/sec
prop in object
if ('pronic' in window.checkObjectTestExample) {
  window.checkObjectTestExample.pronic = 56;
}
ready
typeof object
if (typeof window.checkObjectTestExample.pronic !== 'undefined') {
  window.checkObjectTestExample.pronic = 56;
}
ready
!(object.property)
if (!(window.checkObjectTestExample.pronic)) {
  window.checkObjectTestExample.pronic = 56;
}
ready

Revisions

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