Home >Web Front-end >JS Tutorial >A brief analysis of the delete operator in JavaScript_Basic knowledge
The delete operator will delete the properties, array elements or variables of the object specified by the operand. It will return true if the delete operation is successful,
if the operand cannot be deletedIt will return false. Not all properties and variables can be deleted. Some internal core properties and client properties cannot be deleted. Users declared with the var statement
Defined variables cannot be deleted either. If the operand used by delete is a non-existent property, it will return true (the ECMAScript standard stipulates that when the delete operation is
It will return true when the operand is not a property, array element or variable).
var o = {x:1, y: 2}; //Define a variable
delete o.x; //Delete the x attribute of the o object and return true
typeof o.x; //Return undefined
delete o.x; //return true
delete o; //Variables cannot be deleted
delete 1; //The integer variable value 1 cannot be deleted
x = 1;
delete x; //Can be deleted, return true