JScript Operator Precedence

Source: Internet
Author: User
Tags bitwise expression
js|jscript| operations

Operator Precedence in JScript is a set of rules. This rule controls the order in which operators are executed when evaluating an expression. Operations with higher precedence are performed Fuxian to lower-priority operators. For example, multiplication is performed prior to addition.

The following table lists the JScript operators by priority from highest to lowest. Operators with the same precedence are evaluated in order from left to right.

Operator description
. [] () field access, array subscript, function call, and expression grouping
++--~! Delete new typeof void Unary operator, return data type, object creation, undefined value
*/% multiplication, division, modulo
+-+ addition, subtraction, string concatenation
<< >> >>> Shift
< <= > >= instanceof is less than, less than, greater than, greater than or equal to, instanceof
= =!= = =!== equals, does not equal, strictly equal, not strictly equal
& Bitwise AND
^ per-bitwise XOR OR
| by bit or
&& Logic and
|| Logical OR
?: Conditions
= op= Assignment, Operation assignment
, multiple evaluation

Parentheses can be used to change the order of evaluation that is determined by operator precedence. This means that the expression in parentheses should be evaluated before it is used for the remainder of the expression.

For example:

z = 78 * (96 + 3 + 45)
There are five operators in the expression: =, *, (), +, and another +. According to the rules of operator precedence, they will be evaluated in the following order: (), +, +, *, =.

First evaluate the expression inside the parentheses. There are two addition operators in parentheses. Because the two addition operators have the same precedence, they are evaluated from left to right. Add 96 and 3 first, then add them together with 45, and the result is 144.
Then there is the multiplication operation. 78 times 144, and the result is 11232.
Finally, the assignment operation. Assign 11232 to Z.



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.