delete vs undefined vs null (v35)

Revision 35 of this benchmark created by Check if defined before delete 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.

Setup

var o = {
      p: 1
    };

Test runner

Ready to run.

Testing in
TestOps/sec
delete object.property
o.p = 1;
delete o.p;
ready
delete object["property"]
o.p = 1;
delete o["p"];
ready
check if defined
o.p = 1;
if (o.p) {
  o.p = 1;
}
ready
delete if defined
o.p = 1;
if (o.p) {
  delete o.p;
}
ready
object.property = null
o.p = 1;
o.p = null;
ready
object.property = undefined
o.p = 1;
o.p = undefined;
ready

Revisions

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