The examples in this article describe the usage of javascript attribute access expressions. Share it with everyone for your reference. The specific analysis is as follows:
Attribute access expression operation obtains the value of an object attribute or an array element. js defines 2 syntaxes for attribute access:
expression.identifier expression["expression"]
No matter which formal attribute is used to access the expression, the expression before . and [ will be evaluated first. If the evaluation result is null or undefined, the expression will throw a type error exception because these two values Neither can contain any attributes.
Obviously, the way of writing .identifier is simpler. This method is only applicable when the attribute name to be accessed is a legal identifier, and the name of the attribute to be accessed needs to be known. If the property name is a reserved word or contains spaces and punctuation, or is a number (for an array), it must be written in square brackets. When the genus name is a value obtained by operation rather than a fixed value, square brackets must be used.
The ECMASctript specification allows built-in functions to return an lvalue, but custom functions cannot return lvalues.
The precedence and associativity of operators specify their order of operations in complex expressions, but do not specify the order of operations during the calculation of subexpressions. js always calculates expressions strictly from left to right, such as the following code:
w = x + y * z;
will first calculate w, then calculate the values of x, y and z in sequence; then the value of y*z, then add the value of x, and finally copy it to the variable or attribute pointed to by the expression w . Adding parentheses to an expression changes the relationship between multiplication, addition, and assignment operations, but the left-to-right order does not change.
All numbers in js are of floating point type, and the results of division operations are also of floating point type. For example, the result of 5/2 is 2.5.
The remainder operator is usually an integer, but it can also be a floating point number. For example, the result of 6.5%2.1 is 0.2
I hope this article will be helpful to everyone’s JavaScript programming design.