Difference in operator priority between PHP and JavaScript

Source: Internet
Author: User
: This article mainly introduces the differences in operator priorities between PHP and JavaScript. For more information about PHP tutorials, see. Most of the two have the same priority. comparision and assignment operations have slight differences. Comparison operators include >,<, >=, and so on. value assignment operators include =, + =, and * =.

In JS, the comparison operator has a higher priority than the value assignment operator. So foo = 1 <2 result foo = false;

In PHP, the value assignment operator has a higher priority than the comparison operator. So foo = 1 <2 result foo = 1, and the expression is false. Parentheses must be added to achieve the same result as above.

Foo = (1 <2)

Appendix: complete operator priority of PHP and JavaScript

JS

The following table is ordered from highest (19) to lowest (0) precedence.

Precedence Operator type Associativity Inpidual operators
19 Grouping N/ ( … )
18 Member Access Left-to-right … . …
Computed Member Access Left-to-right … [ … ]
New (with argument list) N/ new … ( … )
17 Function Call Left-to-right … ( … )
New (without argument list) Right-to-left new …
16 Postfix Increment N/ … ++
Postfix Decrement N/ … --
15 Logical NOT Right-to-left ! …
Bitwise NOT Right-to-left ~ …
Unary Plus Right-to-left + …
Unary Negation Right-to-left - …
Prefix Increment Right-to-left ++ …
Prefix Decrement Right-to-left -- …
Typeof Right-to-left typeof …
Void Right-to-left void …
Delete Right-to-left delete …
14 Exponentiation Right-to-left … ** …
Multiplication Left-to-right … * …
Division Left-to-right … / …
Remainder Left-to-right … % …
13 Addition Left-to-right … + …
Subtraction Left-to-right … - …
12 Bitwise Left Shift Left-to-right … << …
Bitwise Right Shift Left-to-right … >> …
Bitwise Unsigned Right Shift Left-to-right … >>> …
11 Less Left-to-right … < …
Less Than Or Equal Left-to-right … <= …
Greater Left-to-right … > …
Greater Than Or Equal Left-to-right … >= …
In Left-to-right … in …
Instanceof Left-to-right … instanceof …
10 Equality Left-to-right … == …
Inequality Left-to-right … != …
Strict Equality Left-to-right … === …
Strict Inequality Left-to-right … !== …
9 Bitwise AND Left-to-right … & …
8 Bitwise XOR Left-to-right … ^ …
7 Bitwise OR Left-to-right … | …
6 Logical AND Left-to-right … && …
5 Logical OR Left-to-right … || …
4 Conditional Right-to-left … ? … : …
3 Assignment Right-to-left … = …
… += …
… -= …
… **= …
… *= …
… /= …
… %= …
… <<= …
… >>= …
… >>>= …
… &= …
… ^= …
… |= …
2 Yield Right-to-left yield …
1 Spread N/ ......
0

PHP

Operator Precedence
Associativity Operators Additional Information
Non-associative Clone new Clone andnew
Left [ Array ()
Right ** Arithmetic
Right ++ --~ (Int) (float) (string) (array) (object) (bool )@ Types andincrement/decrement
Non-associative Instanceof Types
Right ! Logical
Left */% Arithmetic
Left + -. Arithmetic andstring
Left <> Bitwise
Non-associative <=> = Comparison
Non-associative =! ===! ==<><=> Comparison
Left & Bitwise andreferences
Left ^ Bitwise
Left | Bitwise
Left && Logical
Left | Logical
Right ?? Comparison
Left ? : Ternary
Right = + =-= * = ** =/=. = % = & = | = ^ = <= >>=> Assignment
Left And Logical
Left Xor Logical
Left Or Logical

The above introduces the differences in the operator priorities between PHP and JavaScript, including the content, and hope to be helpful to friends who are interested in PHP tutorials.

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.