What is literal?
In programming languages, a literal is a way to express a value. For example, "Hello, World! "In many languages, it represents a string literal (string literal), and JavaScript is no exception. For example, for example, 5, true, false, and null, they represent an integer, two boolean values, and an empty object.
At first glance, it may be difficult to define the number of words. In fact, my understanding is that what I can understand at a glance is the number of words. Object literal
An object literal is a list of name-value pairs. Each name-value pair is separated by a comma and enclosed in braces. Each name-Value Pair represents an attribute of an object. Names and values are separated by a colon. Example:
First
SecondPs1: In the comment, I commented out define blank object, which is actually inaccurate. In JavaScript, no object is empty, even {} inherits some objects. prototype attributes and Methods
Ps2: a similar problem occurs in the subsequent constructor. this = {} this indicates that the null Object is not Object. prototype. For details, refer
Ps3: Previously, I used the delete operator to delete global variables. The same object attributes can also be deleted through delete.
Ps4: do not add a comma (,) after the last attribute. An error occurs in the IE browser. When I wrote the Tree component, this Bug was found for N years.
The last 1 P should not forget to end the (;) on the right of the braces (;)
Array literalThe representation of the array literal is similar to that of the object literal. The Code is as follows:
Array literal notation does not have much content: it is just a list of elements separated by commas (,) and the entire list is packaged in square brackets. You can specify any type of values for the array literal, including objects or other arrays. The array literal syntax is very simple, clear, and elegant.
Regular Expression literalThe Regular Expression in JavaScript is also an object, so we can also create a regular expression in a literal way. The example is as follows:
As shown in the above Code: regular expressions have clear syntax and short syntax. Therefore, the literal representation should be given priority when creating regular expressions.
For more information about the regular expression syntax, read the regular expression notes:The literal values I listed are confusing. For strings, values, and boolean values... I will not introduce them one by one. (Stealing laziness)
I was going to put the literal volume and the constructor together, but I thought it was not appropriate. The constructor expanded a lot and it would be messy to put them together, so I split them up.
In case of any errors, please correct me and make progress together!