The delete operator removes the specified property from an object, returns True when it is successfully deleted, or False if it is returned.
If the deleted property does not exist on the object, then delete will not work, but will still return true.
var person = {Age :+, name:"Yangguo", } console.log (person.name) ; // Yangguo Console.log (delete person.name); // true Console.log (Person.name); // undefined Console.log (delete person.girlfriend); // true also returns true if a nonexistent property is deleted
Non-configurable properties: When an attribute is set to not set, the delete operation will have no effect and will return false. Syntax errors are thrown in strict mode.
var person={};object.defineproperty (person,"name", {value: "Yangguo", Configuar:false }); Console.log (person) ; // {name: "Yangguo"}console.log (delete person.name); // falseConsole.log (person.name); // Yangguo
Any property declared using Var cannot be removed from the global scope and function scope. Properties that are not declared with VAR will be deleted
var person = "Yangguo"; Console.log (Delete person); // falseConsole.log (person); // Yangguo = "Red"; Console.log (delete color)//True Console.log (color ); // uncaught referenceerror:color is not defined
The delete operator cannot delete any functions in the global scope (whether the function is from a function declaration or a function expression)
function Fun () {};console.log (delete fun); // falseConsole.log (fun); // ? Fun () {} var func=function() {};console.log (Delete func); // falseConsole.log (func); // ? (){}
JavaScript delete operator