Update translation of 1-js/02-first-steps/07-operators#508
Merged
MartinsYong merged 8 commits intomasterfrom Nov 1, 2019
Merged
Update translation of 1-js/02-first-steps/07-operators#508MartinsYong merged 8 commits intomasterfrom
MartinsYong merged 8 commits intomasterfrom
Conversation
MartinsYong
suggested changes
Oct 28, 2019
|
|
||
| alert( a ); // 2,自增加一次 | ||
| alert( b ); // 2,自增加一次 | ||
| alert( a ); // 2,自加一次 |
| 所以,对此有一些专门的运算符: | ||
|
|
||
| - **自相加** `++` 将变量与 1 相加: | ||
| - **自加** `++` 将变量与 1 相加: |
|
|
||
| ```warn | ||
| 自相加/自相减只能应用于变量。尝试将其应用于数值(比如 `5++`)会报错。 | ||
| 自加/自减只能应用于变量。试一下,将其应用于数值(比如 `5++`)则会报错。 |
| 那么他们有区别吗?有,但只有当我们使用 `++/--` 的返回值时才能看到区别。 | ||
|
|
||
| 让我们来明确了解这一点。我们知道,所有的运算符都有返回值。自相加/自相减也不例外。前置形式返回一个新的值,但后置返回原来的值(做加法/减法之前的值)。 | ||
| 详细点说。我们知道,所有的运算符都有返回值。自加/自减也不例外。前置形式返回一个新的值,但后置返回原来的值(做加法/减法之前的值)。 |
| ``` | ||
|
|
||
| `(*)` 所在的行是前置形式 `++counter`,对 `counter` 做自相加,返回的是新的值 `2`。因此 `alert` 显示的是 `2`。 | ||
| `(*)` 所在的行是前置形式 `++counter`,对 `counter` 做自加运算,返回的是新的值 `2`。因此 `alert` 显示的是 `2`。 |
| 总结: | ||
|
|
||
| - 如果自相加/自相减的值不会被使用,那么两者形式没有区别: | ||
| - 如果自加/自减的值不会被使用,那么两者形式没有区别: |
| alert( counter ); // 2,以上两行作用相同 | ||
| ``` | ||
| - 如果我们想要对变量自相加 **并且** 立刻使用值,那么我们需要使用前置形式: | ||
| - 如果我们想要对变量进行自加操作,**并且** 需要立刻使用自加后的值,那么我们需要使用前置形式: |
|
|
||
| ````smart header="自相加/自相减和其它运算符的对比" | ||
| `++/--` 运算符同样可以在表达式内部使用。它们的优先级比绝大部分的运算符要高。 | ||
| ````smart header="自加/自减和其它运算符的对比" |
|
Please make the requested changes. After it, add a comment "/done". |
Member
|
校对完毕,感谢~ |
Member
Author
|
@MartinsYong DONE, thanks. |
MartinsYong
approved these changes
Nov 1, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目标章节:1-js/02-first-steps/07-operators
当前上游最新 commit:70ca842bef2390bc26d13dea2b856838aa890fe0
所做更改如下: