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/2-first-steps/8-operators/article.md
+12-13Lines changed: 12 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,29 +118,28 @@ Why did unary pluses work before the binary one? As we're going to see soon, tha
118
118
119
119
## Operators precedence
120
120
121
+
If an expression has more than one operator -- their execution order is defined the their *precedence*.
121
122
122
-
В том случае, если в выражении есть несколько операторов -- порядок их выполнения определяется *приоритетом*.
123
+
From the 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. If we're not satisfied with the order, we can use brackets to override the default precedence: `(1 + 2) * 2`.
123
124
124
-
Из школы мы знаем, что умножение в выражении `2 * 2 + 1` выполнится раньше сложения, т.к. его *приоритет* выше, а скобки явно задают порядок выполнения. Но в JavaScript -- гораздо больше операторов, поэтому существует целая [таблица приоритетов](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence).
125
+
There are many operators in JavaScript. For clarity and internal needs there exists a [precedence table](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence). Every operator has a corresponding precedence number. The one with the bigger number executes first. If the precedence is same -- the execution order is from left to right.
125
126
126
-
Она содержит как уже пройденные операторы, так и те, которые мы еще не проходили. В ней каждому оператору задан числовой приоритет. Тот, у кого число больше -- выполнится раньше. Если приоритет одинаковый, то порядок выполнения -- слева направо.
Так как "унарный плюс" имеет приоритет `15`, выше, чем`13`у обычного "сложения", то в выражении `+apples + +oranges`сначала сработали плюсы у `apples` и `oranges`, а затем уже обычное сложение.
142
+
As we can see, the "unary plus" has a priority of `15`, higher than`13`for the ordinary "addition". That's why in the expression `+apples + +oranges`unary pluses worked first, and then the addition.
0 commit comments