In vs undefined for object keys

Benchmark created by Justin on


Preparation HTML

<script>
  var testObject = {
   one: 1,
   two: 2,
   three: 3,
   four: 4,
   five: 5,
   six: 6
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
check for key with in
if ('three' in testObject) {
 var t = testObject.three;
}
ready
check for key with undefined
if (testObject.three) {
 var t = testObject.three;
}
ready
test for non-existent with in
if ('notThere' in testObject) {
 var t = testObject.notThere;
}
ready
test for non-existent with undefined
if (testObject.notThere) {
 var t = testObject.notThere;
}
ready

Revisions

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

  • Revision 1: published by Justin on
  • Revision 2: published by Rycochet on