Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
```js run no-beautify
let a = 1, b = 1;

alert( ++a ); // 2,前置操作符返回最新值
alert( b++ ); // 1,后置操作符返回旧值
alert( ++a ); // 2,前置运算符返回最新值
alert( b++ ); // 1,后置运算符返回旧值

alert( a ); // 2,自增一次
alert( b ); // 2,自增一次
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/07-operators/1-increment-order/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ importance: 5

---

# 后置操作符和前置操作符
# 后置运算符和前置运算符

以下代码中变量 `a`、`b`、`c`、`d` 的最终值分别是多少?

Expand Down
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/08-comparison/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## 比较结果为 Boolean 类型

和其他操作符一样,比较操作符也会有返回值,返回值为布尔值(Boolean)。
和其他运算符一样,比较运算符也会有返回值,返回值为布尔值(Boolean)。

- `true` —— 表示“yes(是)”,“correct(正确)”或“the truth(真相)”。
- `false` —— 表示“no(否)”,“wrong(错误)”或“not the truth(非真相)”。
Expand Down Expand Up @@ -122,7 +122,7 @@ alert( '' == false ); // true

如果我们需要区分 `0` 和 `false`,该怎么办?

**严格相等操作符 `===` 在进行比较时不会做任何的类型转换。**
**严格相等运算符 `===` 在进行比较时不会做任何的类型转换。**

换句话说,如果 `a` 和 `b` 属于不同的数据类型,那么 `a === b` 不会做任何的类型转换而立刻返回 `false`。

Expand All @@ -134,7 +134,7 @@ alert( 0 === false ); // false,因为被比较值的数据类型不同

同样的,与“不相等”符号 `!=` 类似,“严格不相等”表示为 `!==`。

严格相等的操作符虽然写起来稍微长一些,但是它能够很清楚地显示代码意图,降低你犯错的可能性。
严格相等的运算符虽然写起来稍微长一些,但是它能够很清楚地显示代码意图,降低你犯错的可能性。

## 对 null 和 undefined 进行比较

Expand Down
4 changes: 2 additions & 2 deletions 1-js/02-first-steps/10-ifelse/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ if (age > 18) {
alert(accessAllowed);
```

所谓的“条件”或“问号”操作符让我们可以更简短地达到目的
所谓的“条件”或“问号”运算符让我们可以更简短地达到目的

这个操作符通过问号 `?` 表示。有时它被称为三元运算符,被称为“三元”是因为该操作符中有三个操作数。实际上它是 JavaScript 中唯一一个有这么多操作数的操作符
这个运算符通过问号 `?` 表示。有时它被称为三元运算符,被称为“三元”是因为该运算符中有三个操作数。实际上它是 JavaScript 中唯一一个有这么多操作数的运算符

语法:
```js
Expand Down
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/11-logical-operators/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ result = value1 && value2 && value3;
- 将处理每一个操作数时,都将其转化为布尔值。如果结果是 `false`,就停止计算,并返回这个操作数的初始值。
- 如果所有的操作数都被计算过(也就是,转换结果都是 `true`),则返回最后一个操作数。

换句话说,与操作符返回第一个假值,如果没有假值就返回最后一个值。
换句话说,与运算符返回第一个假值,如果没有假值就返回最后一个值。

上面的规则和或运算很像。区别就是与运算返回第一个假值而或操作返回第一个真值。

例如:

```js run
// 如果第一个操作符是真值
// 如果第一个运算符是真值
// 与操作返回第二个操作数:
alert( 1 && 0 ); // 0
alert( 1 && 5 ); // 5

// 如果第一个操作符是假值
// 如果第一个运算符是假值
// 与操作直接返回它。第二个操作数被忽略
alert( null && 5 ); // null
alert( 0 && "no matter what" ); // 0
Expand All @@ -230,7 +230,7 @@ alert( 1 && 2 && null && 3 ); // null
alert( 1 && 2 && 3 ); // 3,最后一个值
```

````smart header="与运算 `&&` 在或操作符 `||` 之前执行"
````smart header="与运算 `&&` 在或运算符 `||` 之前执行"
与运算 `&&` 的优先级比或运算 `||` 要高。

所以代码 `a && b || c && d` 完全跟 `&&` 表达式加了括号一样:`(a && b) || (c && d)`。
Expand Down Expand Up @@ -272,7 +272,7 @@ if (x > 0) {
result = !value;
```

操作符接受一个参数,并按如下运作:
运算符接受一个参数,并按如下运作:

1. 将操作数转化为布尔类型:`true/false`。
2. 返回相反的值。
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/12-while-for/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ if (i > 5) {

……代码会停止运行,并显示有语法错误。

这是不(建议)使用问号 `?` 操作符替代 `if` 语句的另一个原因。
这是不(建议)使用问号 `?` 运算符替代 `if` 语句的另一个原因。
````

## break/continue 标签
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/17-javascript-specials/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ JavaScript 支持以下运算符:
赋值
: 简单的赋值:`a = b` 和合并了其他操作的赋值:`a * = 2`。

按位操作符
按位运算符
: 按位运算符在最低位级上操作 32 位的整数:详见 [文档](mdn:/JavaScript/Reference/Operators/Bitwise_Operators)。

三元运算符
Expand Down
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/05-object-toprimitive/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
```

`"default"`
: 在少数情况下发生,当操作者“不确定”期望值的类型时。
: 在少数情况下发生,当运算符“不确定”期望值的类型时。

例如,二进制加法 `+` 可用于字符串(连接),也可以用于数字(相加),所以字符串和数字这两种类型都可以。因此,当二元加法得到对象类型的参数时,它将依据 `"default"` hint 来对其进行转换。

Expand Down Expand Up @@ -235,14 +235,14 @@ alert(obj + 2); // 22("2" + 2)被转换为原始值字符串 => 级联

## 总结

对象到原始值的转换,是由许多期望以原始值作为值的内建函数和操作符自动调用的
对象到原始值的转换,是由许多期望以原始值作为值的内建函数和运算符自动调用的

这里有三种类型(hint):
- `"string"`(对于 `alert` 和其他需要字符串的操作)
- `"number"`(对于数学运算)
- `"default"`(少数操作符
- `"default"`(少数运算符

规范明确描述了哪个操作符使用哪个 hint。很少有操作符“不知道期望什么”并使用 `"default"` hint。通常对于内建对象,`"default"` hint 的处理方式与 `"number"` 相同,因此在实践中,最后两个 hint 常常合并在一起。
规范明确描述了哪个运算符使用哪个 hint。很少有运算符“不知道期望什么”并使用 `"default"` hint。通常对于内建对象,`"default"` hint 的处理方式与 `"number"` 相同,因此在实践中,最后两个 hint 常常合并在一起。

转换算法是:

Expand Down
2 changes: 1 addition & 1 deletion 1-js/99-js-misc/01-proxy/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ alert(allUsers.has(user)); // false
如我们所见,进行代理后,我们在 `allUsers` 中找不到 `user`,因为代理是一个不同的对象。

```warn header="Proxy 无法拦截严格相等性检查 `===`"
Proxy 可以拦截许多运算符,例如 `new`(使用 `construct`),`in`(使用 `has`),`delete`(使用 `deleteProperty`)等。
Proxy 可以拦截许多操作符,例如 `new`(使用 `construct`),`in`(使用 `has`),`delete`(使用 `deleteProperty`)等。

但是没有办法拦截对于对象的严格相等性检查。一个对象只严格等于其自身,没有其他值。

Expand Down