Home > Web Front-end > JS Tutorial > Usage analysis of javascript attribute access expression_javascript skills

Usage analysis of javascript attribute access expression_javascript skills

WBOY
Release: 2016-05-16 16:02:20
Original
1178 people have browsed it

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"]
Copy after login

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;
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template