Operators
DELETE AND NEW
new
let obj = new ConstructorFunction();
let today = new Date();
function Person(name) {
this.name = name;
}
let john = new Person("John");
console.log(john.name); // John
Creates a blank object.
Sets the prototype of that object to the constructor's prototype.
Executes the constructor function with this pointing to the new object.
Returns the new object (unless constructor explicitly returns another object).
Avoid new with
Primitive types like Number, String, Boolean (use literals instead)
let str = new String("hello"); // avoid
let str = "hello"; // better
Feature new Object.create()
Creates instance from constructor ✅ ❌
Inherits prototype ✅ ✅ (from object, not function)
Simpler prototype-only creation ❌ ✅
delete
Used to remove a property from an object.
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.