In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the role of delete keywords in js". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Delete is the keyword. Used to delete the properties of an object. Syntax: the deleteobject.propertydeleteobject ['property'] delete operator removes the specified property from an object. True is returned when the deletion is successful, otherwise false is returned.
What the delete keyword does:
Delete object attribute syntax: delete object. Attribute
You can delete global variables that are not declared with the var keyword (attributes defined directly on top of window)
Note when using the delete keyword:
The return value type is a Boolean (true/false), and true is returned after deletion.
Delete attributes that do not exist in the object, and the return value is true
Delete the property in the prototype object of the object (cannot be deleted), and the return value is true
Global variables declared with var cannot be deleted, but attributes defined directly on window can be deleted.
Example of delete keyword:
one
2vardog = {
3name: "recruiting money"
4age:14
5}
6move / delete the attributes of the object
7console.log (deletedog.name); / / true
8console.log (dog.name); / / undefined
nine
10Universe / Delete attributes that do not exist in the object
11console.log (deletedog.eat); / / true
twelve
13Universe / deletes attributes in the prototype object of the object
14Object.prototype.play= "play"
15console.log (deleteObject.prototype.play); / / true
sixteen
If there is no variable declared with the var keyword, the variable becomes a global variable by default (becomes a property of window)
18b = "testb"
19console.log (b); / / testb
twenty
21functionfunc () {
22varnum1=10
23num2=20
24}
twenty-five
26func ()
27//console.log (num1); / / error cannot access local variables outside the function body
28console.log (num2); / / 20num2 becomes an attribute of window
twenty-nine
30max / use delete to delete attributes defined directly on window
31console.log (deletenum2); / / true
32//console.log (num2); / / error report
thirty-three
34vara = "testa"
35deleteaterranking / cannot be deleted
36console.log (a); / / testa
thirty-seven
thirty-eight
This is the end of the content of "the role of delete keywords in js". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.