Update article.md

This commit is contained in:
LeviDing 2022-02-04 14:07:02 +08:00 committed by GitHub
parent 9c74908612
commit fc7bfbb993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -194,22 +194,22 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en-U
| Precedence | Name | Sign | | Precedence | Name | Sign |
|------------|------|------| |------------|------|------|
| ... | ... | ... | | ... | ... | ... |
| 16 | unary plus | `+` | | 15 | unary plus | `+` |
| 16 | unary negation | `-` | | 15 | unary negation | `-` |
| 15 | exponentiation | `**` | | 14 | exponentiation | `**` |
| 14 | multiplication | `*` | | 13 | multiplication | `*` |
| 14 | division | `/` | | 13 | division | `/` |
| 13 | addition | `+` | | 12 | addition | `+` |
| 13 | subtraction | `-` | | 12 | subtraction | `-` |
| ... | ... | ... | | ... | ... | ... |
| 3 | assignment | `=` | | 2 | assignment | `=` |
| ... | ... | ... | | ... | ... | ... |
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. As we can see, the "unary plus" has a priority of `15` 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 ## Assignment
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `3`. Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`.
That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`. That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`.