delete
In JavaScript, the delete keyword is a unary operator that removes a property from an object. It returns true when the property is gone afterward, including when it never existed, and false when the property is non-configurable and can’t be removed.
The operator only affects the object’s own properties. After deleting an own property, a read of the same name finds the inherited value from the prototype, if one exists. Deleting an array element leaves a hole, so the array’s .length doesn’t change. The delete operator doesn’t free memory directly. The garbage collector reclaims a value once nothing references it.
In strict mode, which includes modules and class bodies, two cases are errors. Deleting a plain variable name, such as delete count, is a SyntaxError, and deleting a non-configurable property throws a TypeError. In sloppy mode, both fail quietly. Variables declared with let, const, or var can’t be deleted in either mode.
JavaScript delete Keyword Syntax
The delete operator takes a property access in dot or bracket notation:
delete <object>.<property>
delete <object>[<expression>]
JavaScript delete Keyword Examples
The delete operator removes object properties, leaves holes in arrays, and returns false when a property can’t be deleted:
> const user = { name: "Ada", password: "hunter2" };
undefined
> delete user.password
true
> user
{ name: 'Ada' }
> const colors = ["red", "green", "blue"];
undefined
> delete colors[1]
true
> colors
[ 'red', <1 empty item>, 'blue' ]
> colors.length
3
> delete Math.PI
false
Deleting from the array leaves an empty slot. Math.PI is non-configurable, so the REPL’s sloppy mode returns false.
A module runs in strict mode, so the same failed deletion throws:
constants.mjs
delete Math.PI;
Running the module with Node.js shows the error:
$ node constants.mjs
TypeError: Cannot delete property 'PI' of #<Object>
JavaScript delete Keyword Use Cases
- Removing a property from an object before sending or storing it
- Dropping entries from objects used as lookup tables
- Removing a key so an inherited property shows through
- Cleaning up properties that a configuration object shouldn’t expose
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026