Delete operator tests

by podlipensky

JavaScript

var a = 1;
//delete a; //false, because this is declared global variable, i.e. Global is used as Variable Object here and variable "a" appears there through declaration, so it will have DontDelete attribute
console.log(delete a);

b = 2;
//delete b; //true, because it is undeclared assignment, equals to this.b = 2;
console.log(delete b);

(function foo(y){
    //delete arguments; //false, because it is part of VO
    console.log(delete arguments);
    //delete foo.length; //false
    console.log(delete foo.length);
    
    var bar = 1;
    //delete bar; //false
    console.log(delete bar);
    
    //delete y; //false, because it is part of VO
    console.log(delete y);
    
    this.x = 2;
    //delete this.x; //true, because it is part of function's this object, but not VO
    console.log(delete this.x);
})(1)

//the only exception in eval code
eval('var z = 1;');
//delete z; //true, because variables declared in Eval are created as properties of calling context's Variable Object
console.log(delete z);