Home >Web Front-end >JS Tutorial >A brief analysis of the delete operator in JavaScript_Basic knowledge

A brief analysis of the delete operator in JavaScript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:11:271152browse

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 deleted

It 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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn