Introduction to js literal volume, object literal volume access, and keyword in usage 1: literal meaning
A literal represents how this value is expressed. Generally, when a variable is assigned a value, the right side of the equal sign can be considered as a literal.
The literal is divided into string literal, array literal, and
Object literal and function literal ).
Example:
Var test = "hello world! ";
"Hello world! "Is the string literal, and test is the variable name.
2. Object literal volume
There are two access methods for object literal: Example,
Var obj = {
A: 'aaa', // a is an attribute, and 'aaa' is a property value.
B: 'bbb ',
C: 'ccc'
}
Method 1: When obj. a // aaa, for in traverses an object, this method is invalid...
Method 2: obj ['a'] // aaa, which must be enclosed by quotation marks
[The dot method is only applicable when the attribute is a string. If the attribute is a variable, only the latter can be used]
When the attribute is a variable, you can only assign values using the following method:
Var obj = {};
Obj [$ a] = 'value ';
If you write {$ a: 'value'} directly, $ a is parsed into a string.
Iii. keyword in usage
Format: (variable in object)... note ,,,
When "object" is an array, "variable" refers to the "Index" of the array ";
When "object" is an object, "variable" refers to the "attribute" of the object ".