Js delete USES of to delete object properties and variables
- 2020-03-30 03:46:52
- OfStack
1. Object attribute deletion
function fun(){
this.name = 'mm';
}
var obj = new fun();
console.log(obj.name);//mm
delete obj.name;
console.log(obj.name); //undefined
2. Variable deletion
var name = 'lily';
delete name;
console.log(name); //lily
Delelte can't delete a variable directly
3. Variables in the prototype chain cannot be deleted
fun.prototype.age = 18;
delete obj.age;
console.log(obj.age) //18