JavaScript delete operator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.