Merge pull request #3117 from romanstetsyk/master

Update the operator precedence table
This commit is contained in:
Ilya Kantor 2022-08-14 11:27:46 +03:00 committed by GitHub
commit 15dacc13de
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 | | Precedence | Name | Sign |
|------------|------|------| |------------|------|------|
| ... | ... | ... | | ... | ... | ... |
| 15 | unary plus | `+` | | 14 | unary plus | `+` |
| 15 | unary negation | `-` | | 14 | unary negation | `-` |
| 14 | exponentiation | `**` | | 13 | exponentiation | `**` |
| 13 | multiplication | `*` | | 12 | multiplication | `*` |
| 13 | division | `/` | | 12 | division | `/` |
| 12 | addition | `+` | | 11 | addition | `+` |
| 12 | subtraction | `-` | | 11 | subtraction | `-` |
| ... | ... | ... | | ... | ... | ... |
| 2 | assignment | `=` | | 2 | assignment | `=` |
| ... | ... | ... | | ... | ... | ... |
As we can see, the "unary plus" has a priority of `15` which is higher than the `12` 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 `14` which is higher than the `11` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
## Assignment ## Assignment