Javascript attribute access expression usage analysis _ javascript skills

Source: Internet
Author: User
This article mainly introduces the usage of the javascript attribute access expression. The example analyzes the functions and usage of the javascript attribute access expression. For more information, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

The attribute access expression operation obtains the value of an object attribute or an array element. Js defines the syntax in 2 for attribute access:

Expression. identifier expression ["expression"]

No matter what form of attribute access expression is used. and [the previous expression will be calculated first. if the calculation result is null or undefined, the expression will throw a type error because both values cannot contain any attribute.
Obviously, the identifier method is simpler. this method is only applicable to the attribute names to be accessed as valid identifiers, and you need to know the name of the attribute to be accessed. If the attribute name is a reserved word, contains spaces and punctuation marks, or a number (for an array), square brackets must be used. When the owner name is a calculated value rather than a fixed value, square brackets must be used.

Ecmasctrept allows the built-in function to return a left value, but the custom function cannot return the left value.

The priority and combination of operators specify the order in which they are computed in a complex expression. a single subexpression does not specify the order in which the subexpression is computed. Js always calculates the expression strictly in the order from left to right, for example, the following code:

W = x + y * z;

The w is calculated first, and then the values of x, y, and z are calculated in turn; then the values of y * z are added, finally, copy it to the variable or attribute referred to by expression w. Adding parentheses to an expression will change the relationship between multiplication, addition, and assignment, but the order from left to right will not change.
In js, all numbers are float and division results are float. for example, 5/2 results are 2.5.
The remainder operator is usually an integer, but it can also be a floating point. for example, the result of 6.5% 2.1 is 0.2.

I hope this article will help you design javascript programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.