javascript property access expression usage analysis

  • 2020-06-01 08:22:04
  • OfStack

This article illustrates the use of an javascript property access expression. Share with you for your reference. The specific analysis is as follows:

Attribute access expression operation to get the value of an object attribute or an array element. js defines two grammars for property access:


expression.identifier 
expression["expression"]

Regardless of the form of the property used to access the expression, the expression clock before. And [is evaluated first, and if the result is null or undefined, the expression throws a type error exception, because neither value can contain any property.
Obviously, identifier is easier to write, but only if the name of the property you want to access is a valid identifier and you need to know the name of the property you want to access. If the property name is 1 reserved word or contains Spaces and punctuation, or 1 number (in the case of arrays), you must write it in square brackets. When the generic name is an computed value rather than a fixed value, it must be written in square brackets.

The ECMASctript specification allows built-in functions to return 1 lvalue, but custom functions cannot.

The precedence and associativity of operators dictate the order in which they are evaluated in complex expressions, while singlet does not specify the order in which they are evaluated in subexpressions. js always evaluates expressions strictly from left to right, as shown in the following code:


w = x + y * z;

w will be computed first, and then x,y, and z, in turn; This is followed by the value of y*z, plus the value of x, and then copied to the variable or property referred to by the expression w. Adding parentheses to an expression changes the relationship between multiplication, addition, and assignment, but the order from left to right does not change.
All Numbers in js are floating point, and the result of division is floating point, such as 5/2, which is 2.5.
The remainder operator is usually an integer, but can also be a floating point number, such as 6.5%2.1, which results in 0.2

I hope this article has helped you with your javascript programming.


Related articles: