You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/13-switch/article.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,7 @@ alert( "I don't know such values" );
90
90
```
91
91
92
92
````smart header="Any expresion can be a `switch/case` argument"
93
-
Both `switch` and case allow arbitrary expresions.
93
+
Both `switch` and case allow arbitrary expressions.
94
94
95
95
For example:
96
96
@@ -101,14 +101,15 @@ let b = 0;
101
101
switch (+a) {
102
102
*!*
103
103
case b +1:
104
-
alert(1);
104
+
alert("this runs, because +a is 1, exactly equals b+1");
105
105
break;
106
106
*/!*
107
107
108
108
default:
109
-
alert('no-no, see the code above, it executes');
109
+
alert("this doesn't run");
110
110
}
111
111
```
112
+
Here `+a` gives `1`, that's compared with `b + 1` in `case`, and the corresponding code is executed.
112
113
````
113
114
114
115
## Grouping of "case"
@@ -129,7 +130,7 @@ switch (a) {
129
130
case 3: // (*) grouped two cases
130
131
case 5:
131
132
alert('Wrong!');
132
-
alert('Why don't you take a math class?');
133
+
alert("Why don't you take a math class?");
133
134
break;
134
135
*/!*
135
136
@@ -144,7 +145,7 @@ The ability to "group" cases a side-effect of how `switch/case` works without `b
144
145
145
146
## Type matters
146
147
147
-
Let's emphase that the equality check is always strict. The values must be of the same type to match.
148
+
Let's emphasize that the equality check is always strict. The values must be of the same type to match.
148
149
149
150
For example, let's consider the code:
150
151
@@ -169,4 +170,4 @@ switch (arg) {
169
170
170
171
1. For `0`, `1`, the first `alert` runs.
171
172
2. For `2` the second `alert` runs.
172
-
3. But for `3`, the result of the `prompt` is a string `"3"`, which is not strictly equal `===` to the number `3`. So we've got a dead code in `case 3`! The `default` variant will execite.
173
+
3. But for `3`, the result of the `prompt` is a string `"3"`, which is not strictly equal `===` to the number `3`. So we've got a dead code in `case 3`! The `default` variant will execute.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/14-function-basics/article.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -372,7 +372,7 @@ Few examples of breaking this rule:
372
372
- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return).
373
373
- `checkPermission` -- would be bad if displays the `access granted/denied` message (should only perform the check and return the result).
374
374
375
-
These examples assume common meanings of prefixes. What they mean for you is determined by you and your team. Maybe it's pretty normal for your code to behave differently. But you should to have a firm understanding what a prefix means, what a prefixed function can and what it can not do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
375
+
These examples assume common meanings of prefixes. What they mean for you is determined by you and your team. Maybe it's pretty normal for your code to behave differently. But you should have a firm understanding of what a prefix means, what a prefixed function can and what it cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
0 commit comments