➕delete
🚧 under construction -> configurable
Last updated
🚧 under construction -> configurable
Last updated
JS ⟩ statement ⟩ expression ⟩ operator ⟩ unary ⟩ delete
delete
can't delete normal variables. they are considered unqualified❗
only deletes object's own/configurable properties, not inherited ones.
expects its operand to be an lvalue, if it is not an lvalue, the operator takes no action and returns true.
deleting an array element leaves a “hole” in the array and does not change the array’s length❗ (sparse array)
🔰 global variable/function as global object property
these properties cannot be deleted with delete❗
delete <expr>
returns true if <expr>
is not a property access expression.
accidental global variable in sloppy mode❗️ - can be deleted by delete.
array elements can be deleted with the delete operator.
replit:delete in sloppy/strict mode
// '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.