delete of an unqualified identifier in strict mode❗️

only object's configurable properties are "qualified" for "delete", other identifiers are "unqualilfied".

JSerrorSyntaxError ⟩ delete of an unqualified identifier in 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.

Last updated