JavaScript Property access Expression usage analysis

Source: Internet
Author: User

JavaScript Property access expression usage Analysis

This article mainly introduces JavaScript attribute access expression Usage, example analysis JavaScript attribute access expression function and use method, need friend can refer to the following

This example describes the use of JavaScript property access expressions. Share to everyone for your reference. The specific analysis is as follows:

A property access expression operation gets the value of an object property or an array element. JS defines 2 syntax for property access:

?

1 2 Expression.identifier expression["expression"]

No matter what form a property access expression is used, the expression clock before. And [evaluates first, and if the result is null or undefined, the expression throws a type error exception because neither of these values can contain any properties.

Obviously. Identifier's writing is simpler, and this method only works if the property name to be accessed is a valid identifier, and you need to know the name of the property you want to access. If the property name is a reserved word or contains spaces and punctuation marks, or a number (for an array), you must use the square bracket notation. When a name is a value that is calculated by an operation rather than a fixed value, the square brackets must be used.

The ECMASCTRIPT specification allows built-in functions to return a left value, but the custom function cannot return the left value.

The precedence and binding of operators specify their order of operations in complex expressions, and they do not specify the order of operations in the subexpression evaluation process. JS always evaluates the expression strictly in left-to-right order, such as the following code:

?

1 w = x + y * z;

The W is evaluated first, then the value of X,y and Z, followed by the value of the y*z, followed by the value of x, and finally copied to the variable or property that the expression W refers to. Adding parentheses to an expression changes the relationship between multiplication, addition, and assignment operations, but the order from left to right does not change.

JS all the numbers are floating-point type, the result of division is also floating-point, such as 5/2 result is 2.5.

The remainder operator is usually an integer, but it can also be a floating-point number, such as a 6.5%2.1 result of 0.2

I hope this article will help you with your JavaScript programming.

Related Article

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.