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/07-operators/article.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -127,11 +127,11 @@ Why are unary pluses applied to values before the binary ones? As we're going to
127
127
128
128
## Operator precedence
129
129
130
-
If an expression has more than one operator, the execution order is defined by their *precedence*, or, in other words, the implicit priority order of operators.
130
+
If an expression has more than one operator, the execution order is defined by their *precedence*, or, in other words, the default priority order of operators.
131
131
132
132
From school, we all know that the multiplication in the expression `1 + 2 * 2` should be calculated before the addition. That's exactly the precedence thing. The multiplication is said to have *a higher precedence* than the addition.
133
133
134
-
Parentheses override any precedence, so if we're not satisfied with the implicit order, we can use them to change it. For example: `(1 + 2) * 2`.
134
+
Parentheses override any precedence, so if we're not satisfied with the default order, we can use them to change it. For example, write `(1 + 2) * 2`.
135
135
136
136
There are many operators in JavaScript. Every operator has a corresponding precedence number. The one with the larger number executes first. If the precedence is the same, the execution order is from left to right.
137
137
@@ -199,9 +199,9 @@ alert( a ); // 3
199
199
alert( c ); // 0
200
200
```
201
201
202
-
In the example above, the result of `(a = b + 1)` is the value which is assigned to `a` (that is `3`). It is then used to subtract from `3`.
202
+
In the example above, the result of expression `(a = b + 1)` is the value which was assigned to `a` (that is `3`). It is then used for further evaluations.
203
203
204
-
Funny code, isn't it? We should understand how it works, because sometimes we see it in3rd-party libraries, but shouldn't write anything like that ourselves. Such tricks definitely don't make code clearer or readable.
204
+
Funny code, isn't it? We should understand how it works, because sometimes we see it inJavaScript libraries, but shouldn't write anything like that ourselves. Such tricks definitely don't make code clearer or readable.
205
205
````
206
206
207
207
## Remainder %
@@ -427,10 +427,10 @@ Here, the first expression `1 + 2` is evaluated and its result is thrown away. T
427
427
```smart header="Comma has a very low precedence"
428
428
Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above.
429
429
430
-
Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and finally the number after the comma, `7`, is not processed so it's ignored.
430
+
Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and the rest is ignored. It's like `(a = 1 + 2), 3 + 4`.
431
431
```
432
432
433
-
Why do we need an operator that throws away everything except the last part?
433
+
Why do we need an operator that throws away everything except the last expression?
434
434
435
435
Sometimes, people use it in more complex constructs to put several actions in one line.
436
436
@@ -443,4 +443,4 @@ for (*!*a = 1, b = 3, c = a * b*/!*; a < 10; a++) {
443
443
}
444
444
```
445
445
446
-
Such tricks are used in many JavaScript frameworks. That's why we're mentioning them. But, usually, they don't improve code readability so we should think well before using them.
446
+
Such tricks are used in many JavaScript frameworks. That's why we're mentioning them. But usually they don't improve code readability so we should think well before using them.
0 commit comments