A brief analysis of the delete operator in JavaScript

  • 2020-03-30 00:39:14
  • OfStack

The delete operator deletes an attribute, array element, or variable of an object specified by the operand. If the delete operation succeeds, it will return true. If the operand cannot be deleted,

It will return false. Not all properties and variables can be deleted, some internal core properties and client properties can not be deleted, with var statement of the user

Defined variables cannot be deleted. If the operand used by delete is a nonexistent property, it will return true(the ECMAScript standard states that when delete is evaluated

It returns true when the operand is not an attribute, an array element, or a variable.

    Var o = {x:1, y: 2};       // define a variable

    The delete o.x;                             // returns true by deleting the x attribute of the o object

    The typeof o.x;                             / / returns undefined

    The delete o.x;                           / / return true

    The delete o;                               // cannot delete a variable

    Delete 1;                           // the value of an integer variable 1 cannot be deleted

      X = 1;                                     //

      Delete the x;                       // can be deleted, return true

Related articles: