Lecture JS - Operator
Lecture JS - Operator
function Person(name) {
this.name = name;
}
delete object.property;
let person = {
name: "Alice",
age: 30
};
delete person.age;
console.log(person); // { name: "Alice" }
Only works on object properties, not variables declared with var, let, or const.
Returns true if the property is successfully deleted or doesn't exist.
Does not affect prototype chain properties.
Deleting array elements creates holes (i.e., leaves undefined values), which can be confusing.