Check if object has property

Benchmark created by Bill Heaton on


Description

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

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

Revisions

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