Introduction to operator priority in JavaScript _ javascript skills

Source: Internet
Author: User
This article briefly introduces the priority of operators in JavaScript, which is very practical. For more information, see. Operator priority

The operator priority in JavaScript is a set of rules. This rule controls the order in which operators are executed when calculating expressions. Operators with higher priority are executed before operators with lower priority. For example, multiplication is performed before addition.

The following table lists JavaScript operators based on the highest to lowest priority. Operators with the same priority are evaluated from left to right.


Operator Description
. [] () Field access, array subscript, function call, and expression grouping
++ ---~ ! Delete new typeof void Unary operator, returned data type, object creation, undefined Value
*/% Multiplication, division, modulo
+-+ Addition, subtraction, string connection
<>>>> Shift
<<=>> = Instanceof Less than, less than or equal to, greater than, greater than or equal to, instanceof
=! ===! = Equal to, not equal to, strictly equal, not strictly equal
& Bitwise AND
^ Bitwise OR
| By bit or
&& Logic and
| Logic or
? : Condition
= OP = Assignment and operation assignment
, Multiple evaluate

Parentheses can be used to change the order of evaluation determined by the operator priority. This means that the expressions in parentheses should be evaluated before they are used for the rest of the expressions.

z = 78 * (96 + 3 + 45)

There are five operators in this expression: =, *, (), +, and another +. Based on the operator priority rules, they are evaluated in the following order: (), +, +, *, =.

Evaluate the expressions in parentheses. There are two addition operators in parentheses. Because the two addition operators have the same priority, they are evaluated from left to right. Add 96 and 3 first, and then add them to 45. The result is 144.
Then there is a multiplication operation. Multiply 78 by 144, and the result is 11232.
A is the value assignment operation. Grant the value 11232 to z.

The above is all the content of this article. I hope you will like it.

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.