Merge pull request #2839 from ruslauz/fix/operator-precedence

fixes operator precedence
This commit is contained in:
Ilya Kantor 2022-02-03 13:28:16 +03:00 committed by GitHub
commit 843f945aa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -194,18 +194,18 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en-U
| Precedence | Name | Sign |
|------------|------|------|
| ... | ... | ... |
| 17 | unary plus | `+` |
| 17 | unary negation | `-` |
| 16 | exponentiation | `**` |
| 15 | multiplication | `*` |
| 15 | division | `/` |
| 16 | unary plus | `+` |
| 16 | unary negation | `-` |
| 15 | exponentiation | `**` |
| 14 | multiplication | `*` |
| 14 | division | `/` |
| 13 | addition | `+` |
| 13 | subtraction | `-` |
| ... | ... | ... |
| 3 | assignment | `=` |
| ... | ... | ... |
As we can see, the "unary plus" has a priority of `17` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `+apples + +oranges`, unary pluses work before the addition.
As we can see, the "unary plus" has a priority of `16` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
## Assignment