delete vs undefined vs null (v32)

Revision 32 of this benchmark created by Arjun on


Description

The delete operator removes a property entirely. Setting a property to undefined removes the value. Setting a property to null changes the value to the null value.

Technically they are not equivalent, but in practice they are often used to mean the same thing: that a property is unset.

Preparation HTML

<script>
  o = {};
  o.p = 1;
  
  function reset() {
   o.p = 1;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
delete object.property
delete o.p;
reset();
ready
delete object["property"]
delete o["p"];
reset();
ready
object.property = undefined
o.p = undefined;
reset();
ready
object["property"] = undefined
o["p"] = undefined;
reset();
ready
object.property = null
o.p = null;
reset();
ready
object["property"] = null
o["p"] = null;
reset();
ready
Object.defineProperty undefined non-enumerable
  Object.defineProperty(o, "p", {
    enumerable: false,
    value: undefined
  });
ready

Revisions

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