delete vs undefined vs null (v23)

Revision 23 of this benchmark created by Dan 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

function O() {};
    O.prototype = {
      p: null
    };
    
    var o = new O();
    o.p = 1;

Test runner

Ready to run.

Testing in
TestOps/sec
Delete
 delete o.p;
ready
Set to False
 o.p = false;
ready
Set to Zero
o.p = 0;
ready
Set to Null
 o.p = null;
ready
Set to Undefined
 o.p = undefined;
ready
Set to void 0
o.p = void 0;
ready

Revisions

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