delete vs undefined vs null (v27)

Revision 27 of this benchmark created by Gary 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 = {};
    for (var i = 0; i < 1000; i++) {
      o['p' + i] = i;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
delete object.property
 delete o.p;
ready
delete object["property"]
for (var i = 0; i < 1000; i++) {
  delete o["p" + i];
}
ready
object.property = false
 o.p = false;
ready
object["property"] = false
for (var i = 0; i < 1000; i++) {
 o["p" + i] = false;
}
ready
object.property = null
 o.p = null;
ready
object.property = undefined
 o.p = undefined;
ready
object["property"] = undefined
for (var i = 0; i < 1000; i++) {
  o["p" + i] = undefined;
}
ready

Revisions

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