On the precedence _javascript techniques of operators in JavaScript

Source: Internet
Author: User
Tags bitwise

Operator Precedence

Operator precedence in JavaScript 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 JavaScript operators by priority from highest to lowest. Operators with the same precedence are evaluated in order from left to right.


Operator Describe
. [] () field access, array subscripts, function calls, and expression groupings
++ -- - ~ ! Delete new typeof void Unary operator, return data type, object creation, undefined value
* / % Multiplication, division, modulo
+ - + addition, subtraction, string concatenation
<< >> >>> Shift
< <= > >= instanceof Less than, less than or equal to, greater than, greater than or equal to, instanceof
== != === !== Equal, not equal to, strictly equal, not strictly equal
& Bitwise AND
^ Per-bitwise XOR OR
| by bit or
&& Logic and
|| Logical OR
?: Conditions
= op= Assignment, assignment of operations
, 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.

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.
A finally, the assignment operation. Assign 11232 to Z.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.