delete vs undefined vs null (v9)

Revision 9 of this benchmark created 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 = {
   p: 1
  };
  var id = 0

</script>

Test runner

Ready to run.

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

Revisions

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