JavaScript basic syntax--precedence of operators

Source: Internet
Author: User
Tags bitwise

In all operations, there is a sequence of operations. When I was a child, when we learned arithmetic, we all knew a rule: first multiplication and then minus, parentheses are the braces!

Similarly, in JavaScript, the operator's precedence is shown in the table below, with precedence higher than the following

Operator Operation
++ Self-increment (note the difference before and after)
-- Self-reduction (note the difference before and after)
- Negation (for numbers)
+ Convert to Digital
~ Bitwise negation
! Logical Non-
Delete, typeof, void Delete the property, check the data type, return the value of undefined
*, /, %
Multiply, divide, seek redundancy
+, - Add, Subtract
+ String connection
<<, >>, >>> Left shift, signed right shift, unsigned right shift
<, <=, >= Compare size, first than number, after letter
== Judging if they are equal
!= Judging whether it's unequal
=== Determine if the identity is identical
!== Determine if you are not identical
& Bitwise-AND
^ Bitwise XOR OR
| Bitwise OR
&& Logic and
|| Logical OR
?: Conditional operators
= Assignment operators
op= Operation and Assignment

Here's a chestnut.

var a = {N:1}; var b == a = {N:2//  undefined//  {N:2}//  A = = {N:2}//  b = ={/        //        x: {N:2}
    //      }

Analytical:
Although the assignment operator is evaluated right-to-left, there is also a very important test point: The precedence of the operator

The dot operation is better than the = assignment operation, so a.x = a = {N:2} can be understood as:

1). Declares the x attribute in the A object, while B and a simultaneously point to the object {N:1, x:undefined}, which has an unassigned X at the same time
2). Assign values from right to left
1>. Assign a value to a object--a = {N:2}, at which point the variable name a changes to the new object {N:2}
2>. For a.x (which can be understood as b.x, that is, A.x has determined the point, so it is not affected by the 1> Step) property assignment {N:2}, at this time object B, {N:1, X:{n:2}}

JavaScript basic syntax--precedence of operators

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.