> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/obj/prop/create/delete.md).

# delete

🚧 under construction -> configurable

* [JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md) ⟩ [property](/web/js/val/obj/prop.md) ⟩ [access](/web/js/val/obj/prop/access.md) ⟩ delete
* [JS](/web/js.md) ⟩ [statement](/web/js/grammar/statement.md) ⟩ [expression](/web/js/grammar/statement/expr.md) ⟩ [operator](/web/js/grammar/op.md) ⟩ [unary](/web/js/grammar/op/unary.md) ⟩ delete

{% hint style="success" %}
([unary operator](/web/js/grammar/op/unary.md))&#x20;

<mark style="color:purple;">**deletes**</mark> <mark style="color:red;">**configurable**</mark> [property](/web/js/val/obj/prop.md) <mark style="color:yellow;">**/**</mark> [element](/web/js/val/builtin/arr/element.md).  &#x20;

```javascript
delete <expr>
// ⭐️ return true if `expr` is not a "property access expression"
```

:point\_right: [table of operators](/web/js/grammar/op/table-of-operators.md)
{% endhint %}

{% tabs %}
{% tab title="🗺️" %} <img src="https://2527454625-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfvEFZnSBhKT6fJmus0%2Fuploads%2FzUGyMtQEO9EbjmoCTsPZ%2Fdelete.property.svg?alt=media&amp;token=e96fbe97-32ed-43d6-94c3-33cba5f95c79" alt="deleting property" class="gitbook-drawing">
{% endtab %}

{% tab title="⭐️" %}
{% hint style="danger" %} <mark style="color:purple;">**delete**</mark> &#x20;

* <mark style="color:red;">**can't**</mark>**&#x20;**<mark style="color:yellow;">**delete normal**</mark> [**variables**](/web/js/variable.md). they are considered [**unqualified**](/web/js/val/obj/prop/create/delete/unqualified-for-delete.md):exclamation:
* <mark style="color:red;">**only**</mark>**&#x20;**<mark style="color:yellow;">**deletes**</mark> object's <mark style="color:red;">**own**</mark><mark style="color:yellow;">**/**</mark><mark style="color:red;">**configurable**</mark>**&#x20;**<mark style="color:yellow;">**properties**</mark>, <mark style="color:red;">**not inherited**</mark>**&#x20;**<mark style="color:yellow;">**ones**</mark>.
* expects its <mark style="color:yellow;">**operand**</mark> to be an [lvalue](/web/js/grammar/op/term/lvalue.md), <mark style="color:red;">**if**</mark> it is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**an lvalue**</mark>, the operator <mark style="color:yellow;">**takes**</mark>**&#x20;**<mark style="color:red;">**no**</mark>**&#x20;**<mark style="color:yellow;">**action**</mark> and <mark style="color:yellow;">**returns**</mark>**&#x20;**<mark style="color:green;">**true**</mark>.
  {% endhint %}

{% hint style="warning" %} <mark style="color:purple;">**deleting**</mark> an array [element](/web/js/val/builtin/arr/element.md) leaves a “<mark style="color:yellow;">**hole**</mark>” in the array and <mark style="color:red;">**does not**</mark>**&#x20;**<mark style="color:yellow;">**change**</mark> the array’s <mark style="color:yellow;">**length**</mark>:exclamation: ([sparse array](/web/js/val/builtin/arr/sparse.md))
{% endhint %}

{% hint style="warning" %}
:beginner: <mark style="color:orange;">**global variable/function**</mark>**&#x20;**<mark style="color:yellow;">**as**</mark>**&#x20;**<mark style="color:blue;">**global object property**</mark>

* <mark style="color:yellow;">**these**</mark> <mark style="color:yellow;">**properties**</mark> <mark style="color:red;">**cannot**</mark> be <mark style="color:yellow;">**deleted**</mark> with <mark style="color:purple;">**delete**</mark>:exclamation:

👉 [global var / function is global object property❗️](/web/js/variable/declare/var/is-global-obj-prop.md)
{% endhint %}
{% endtab %}

{% tab title="🔴" %}

* [unqualified identifier for delete](/web/js/val/obj/prop/create/delete/unqualified-for-delete.md).
  * [delete of an unqualified identifier in strict mode❗️](/web/js/err/syntax/delete-of-an-unqualified-identifier-in-strict-mode.md)
* [can't delete variable/function❗️](/web/js/variable/delete.md)
  {% endtab %}

{% tab title="👥" %}

* <mark style="color:purple;">**delete**</mark> `<expr>` <mark style="color:yellow;">**returns true**</mark> <mark style="color:red;">**if**</mark> `<expr>` <mark style="color:yellow;">**is**</mark>**&#x20;**<mark style="color:red;">**not**</mark> a [**property access expression**](/web/js/val/obj/prop/access/property-access-expression.md).
* [accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md) - can be deleted by <mark style="color:purple;">**delete**</mark>.
* [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md)
* **array** [**elements**](/web/js/val/builtin/arr/element.md) can be <mark style="color:yellow;">**deleted**</mark> with the <mark style="color:purple;">**delete**</mark> operator.
  {% endtab %}

{% tab title="💈" %}

* replit：[delete in sloppy/strict mode](https://replit.com/@pegasusroe/delete-in-sloppystrict-mode#index.js)

```javascript
// 'use strict';    // ⭐ toggle sloppy/strict mode

const { log } = console;

// declarations
let x = 3.14;                            // variable
function f1() { log('f1'); }             // function declaration
let f2 = function() { log('f2'); }       // function expression
let fruits = ["Banana", "Orange"];       // array
let person = { name: 'John', age: 18 };  // object

// log
[
    //            mode:  //  sloppy                strict
    // -----------------------------------------------------------
    delete x,            // ❌ false               ⛔ SyntaxError
    x,                   // 3.14

    delete f1,           // ❌ false               ⛔ SyntaxError
    f1,                  // [Function: f1]

    delete f2,           // ❌ false               ⛔ SyntaxError
    f2,                  // [Function: f2]

    delete fruits[1],    // ✅ true                 ✅ true
    fruits,              // ['Banana', <empty>]     ['Banana', <empty>]

    delete person.age,   // ✅ true                 ✅ true
    person,              // { name: 'John' }        { name: 'John' }
    
].forEach(x => console.log(x));

// ⛔ SyntaxError: Delete of an unqualified identifier in strict mode.
```

{% endtab %}

{% tab title="📗" %}
\*
\[ ]
[JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩&#x20;

```
* [ ] 4.13.4 The delete Operator
* [ ] 6.4 Deleting Properties
```

* [ ] itHome ⟩ [你不可不知的 JavaScript 二三事](https://ithelp.ithome.com.tw/users/20112483/ironman/2016) ⟩&#x20;
  * [ ] [#Day12：看 Strict Mode 如何施展「還我漂亮拳」(1)](https://ithelp.ithome.com.tw/articles/10205275)
    {% endtab %}

{% tab title="📘" %}

* [delete operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete)
  {% endtab %}

{% tab title="🗣" %}

* [How can I unset a JavaScript variable?](https://stackoverflow.com/questions/1596782/how-can-i-unset-a-javascript-variable)
  {% endtab %}
  {% endtabs %}
