Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The delete operator is a unary operator used to remove an own property from an object. When successful, it severs the binding between the property key and the target object. If no property with the same key exists in the object’s prototype chain, subsequent accesses to that key will evaluate to undefined; otherwise, the deletion of the own property will expose the inherited property from the prototype.
delete object.property;
delete object['property'];

Return Value

The operator evaluates to a Boolean value:
  • true: Returned if the property was successfully deleted, or if the property did not exist on the target object.
  • false: Returned in non-strict mode if the property exists but cannot be deleted.

Technical Mechanics

1. The [[Configurable]] Attribute For properties that exist on the target object, the delete operator only succeeds if the internal property descriptor attribute [[Configurable]] is set to true. It will also succeed (return true) if the property key does not exist on the object at all. Built-in properties of standard objects (like Math.PI) and properties created via Object.defineProperty() with configurable: false cannot be deleted.
const obj = {};
Object.defineProperty(obj, 'lockedProp', {
  value: 42,
  configurable: false
});

delete obj.lockedProp; // Returns false (or throws in Strict Mode)
delete obj.nonExistent; // Returns true
console.log(obj.lockedProp); // 42
2. Strict Mode Behavior In strict mode ("use strict";), attempting to delete a non-configurable property, or attempting to delete an unqualified identifier (e.g., delete myVar), throws a TypeError or SyntaxError instead of silently returning false. 3. Variables and Functions The delete operator operates exclusively on object properties. It cannot remove bindings from declarative environment records. Therefore, variables declared with var, let, or const, and functions declared via function declarations, cannot be deleted.
var x = 10;
let y = 20;
function z() {}

delete x; // false (SyntaxError in strict mode)
delete y; // false (SyntaxError in strict mode)
delete z; // false (SyntaxError in strict mode)
Note: Implicit globals (variables assigned without declaration in non-strict mode) are created as configurable properties on the global object and can be deleted. 4. Prototype Chain Resolution delete only mutates the target object directly; it does not traverse the prototype chain. If an object and its prototype share a property key, deleting the own property on the object will expose the inherited property from the prototype.
function Foo() {}
Foo.prototype.bar = 42;

const instance = new Foo();
instance.bar = 99;

delete instance.bar; // Returns true (deletes own property)
console.log(instance.bar); // 42 (resolves to prototype property)
delete instance.bar; // Returns true (does nothing, property is not on instance)
console.log(instance.bar); // 42 (prototype remains unaffected)
5. Array Mutation When applied to an array index, delete removes the element but does not update the array’s length property or shift subsequent elements. This creates a “sparse array” containing an empty slot (a hole).
const arr = ['a', 'b', 'c'];
delete arr[1]; // Returns true

console.log(arr.length); // 3
console.log(arr); // ['a', empty, 'c']
console.log(arr[1]); // undefined
6. Memory Management The delete operator does not directly free memory. It only removes the property reference from the object. The underlying value will only be reclaimed by the garbage collector if no other references to that value exist in memory.
Master JavaScript with Deep Grasping Methodology!Learn More