File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
1-js/02-first-steps/13-switch Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
# "switch" 语句
2
2
3
- ` switch ` 语句可以被多个 ` if ` 语句替代 。
3
+ ` switch ` 语句可以替代多个 ` if ` 判断 。
4
4
5
5
` switch ` 语句为多分支选择的情况提供了一个更具描述性的方式。
6
6
@@ -87,7 +87,7 @@ alert( 'Too big' );
87
87
alert ( " I don't know such values" );
88
88
```
89
89
90
- ````smart header="Any expression can be a ` switch/case ` argument "
90
+ ````smart header="任何表达式都可以是 ` switch/case ` 的参数 "
91
91
` switch ` 和 ` case ` 都允许任意表达式。
92
92
93
93
比如:
@@ -107,7 +107,7 @@ switch (+a) {
107
107
alert (" this doesn't run" );
108
108
}
109
109
```
110
- Here ` +a ` gives ` 1 ` , that's compared with ` b + 1 ` in ` case ` , and the corresponding code is executed.
110
+ 这里 ` +a ` 返回 ` 1 ` ,这个值跟 ` case ` 中 ` b + 1 ` 相比较,然后对应代码被执行。
111
111
````
112
112
113
113
## "case" 分组
@@ -139,9 +139,9 @@ switch (a) {
139
139
140
140
现在 `3` 和 `5` 都显示相同的信息。
141
141
142
- 在没有 `break` 的情况下,`switch/case` 会 “分组” case。 因为没有 `break`,`case 3` 会从 `(*)` 行执行到 `case 5`。
142
+ 在没有 `break` 的情况下,`switch/case` 会对 case “分组”。 因为没有 `break`,`case 3` 会从 `(*)` 行执行到 `case 5`。
143
143
144
- ## 值类型
144
+ ## 类型很关键
145
145
146
146
强调一下,这里的相等是严格相等。被比较的值必须是相同类型的才能匹配。
147
147
You can’t perform that action at this time.
0 commit comments