Course contentsShow
← JavaScript
Lesson 605 of 2,72315. ObjectsFree lesson

Deleting Properties with the delete Operator

Remove properties from objects and understand delete's return value and limitations.

Deleting Properties with the delete Operator

What you'll learn: How to remove properties from objects using the delete operator and what it actually returns.

Sometimes you need to completely remove a property from an object, not just set it to null or undefined. The delete operator does exactly this—it removes a property entirely, as if it never existed.

How delete Works

The syntax is simple:

let user = {
  name: "Alice",
  age: 30,
  email: "alice@example.com"
};

delete user.age;

console.log(user); // { name: "Alice", email: "alice@example.com" }
console.log(user.age); // undefined (property doesn't exist anymore)

You can use delete with both dot and bracket notation:

let settings = {
  theme: "dark",
  language: "en"
};

delete settings["theme"];
console.log(settings); // { language: "en" }

What delete Returns

The delete operator returns a boolean:

  • true if the deletion succeeded (or the property didn't exist)
  • false if the property cannot be deleted (rare cases with non-configurable properties)
let car = { brand: "Toyota" };

console.log(delete car.brand); // true
console.log(delete car.color);  // true (property didn't exist, still returns true)

Think of It Like This

Imagine an object as a filing cabinet. Setting a property to undefined is like putting an empty folder in a drawer—the label still exists. Using delete removes the drawer label entirely.

Key Takeaway: Use delete objectName.propertyName to completely remove a property from an object; it returns true on success and the property will no longer exist (not even as undefined).