The delete operator is arguably an old language feature of JavaScript. As it literally means, it wants to destroy something, but what exactly can be destroyed?

## delete 0

When delete 0 is executed, will it be destroyed from the execution system from 0?

Obviously not, its real purpose is to delete a property reference of an object.

```javascript
delete object.property;
delete object['property'];
```

Generally, successful deletion will return true and failure will return false, but there are some exceptions.

## Own properties

The delete operator only works on its own property. If there is a property with the same name on the prototype chain, this property will be skipped.

![JavaScript delete operator example showing own property deletion vs prototype chain properties](https://img.upweb.dev/content/963f60ff-977x480.png)

## Non-existent property

If the deleted property does not exist, delete will have no effect, but will still return true.

```javascript
const object = {};
delete object.name; // true
```

## Non-configurable property

Non-configurable properties cannot be removed.

![JavaScript delete operator example showing non-configurable property deletion failure in non-strict mode](https://img.upweb.dev/content/9359aa74-826x468.png)

In non-strict mode, removing a non-configurable property of itself will return false, but in strict mode, it will throw a TypeError.

![JavaScript delete operator example showing TypeError when deleting non-configurable property in strict mode](https://img.upweb.dev/content/f266d70f-977x477.png)

## Properties declared by var, let, const

In the global scope, neither properties declared with var nor functions declared with function declarations (non-function expressions) can be deleted. This is because both the declared properties are mounted on the globalThis and are non-configurable, so the logic of the previous item will be followed when deleting.

![JavaScript delete operator example showing var and function declaration deletion restrictions in global scope](https://img.upweb.dev/content/2c236075-883x558.jpg)

In addition, properties declared with var, let, const and those functions cannot be deleted, either in the global scope or in the function scope.

```javascript
{
  let object = {
    name: 1,
  };

  function getName(obj) {
    return obj.name;
  }

  console.log(delete object); // false
  console.log(delete getName); // false
}
```

In non-strict mode, false is returned, **but in strict mode, a SyntaxError is thrown instead of a TypeError.**

![JavaScript delete operator example showing SyntaxError when deleting let const variables in strict mode](https://img.upweb.dev/content/49080361-977x549.png)

## Array property

First of all, the length property of the array is not configurable, so deleting it in strict mode will throw a **TypeError**.

![JavaScript delete operator example showing TypeError when attempting to delete array length property](https://img.upweb.dev/content/5c085213-840x323.jpg)

In addition, when deleting an array element, the deleted item will be empty.

![JavaScript delete operator example showing array element deletion creating empty slots](https://img.upweb.dev/content/916311f5-733x171.jpg)

## Conclusion

The real purpose of the 'delete operator' in JavaScript is to delete a property reference of an object. It can behave strangely in some special cases, so it's best to only use it to remove configurable properties that exist on the object itself.

Additionally, when you remove a property from an object, and this property's value is an object without any remaining references, the JavaScript runtime will eventually automatically free the object owned by that property. For more insights into programming language memory management, see my previous article.

_If you found this helpful, consider [subscribing to my newsletter](https://upweb.dev) for weekly web development insights and updates. Thanks for reading!_
