From dad2d807de579dcb717d0214d673a798227eec83 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Tue, 17 Jul 2018 11:59:02 +0300 Subject: [PATCH] fix precedence --- 1-js/02-first-steps/11-logical-operators/article.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/11-logical-operators/article.md b/1-js/02-first-steps/11-logical-operators/article.md index 4ccb4fea..d2431494 100644 --- a/1-js/02-first-steps/11-logical-operators/article.md +++ b/1-js/02-first-steps/11-logical-operators/article.md @@ -230,14 +230,10 @@ When all values are truthy, the last value is returned: alert( 1 && 2 && 3 ); // 3, the last one ``` -````smart header="AND `&&` executes before OR `||`" -The precedence of the AND `&&` operator is higher than OR `||`, so it executes before OR. +````smart header="Precedence of AND `&&` is higher than OR `||`" +The precedence of AND `&&` operator is higher than OR `||`. -In the code below `1 && 0` is calculated first: - -```js run -alert( 5 || 1 && 0 ); // 5 -``` +So the code `a && b || c && d` is essentially the same as if `&&` were in parentheses: `(a && b) || (c && d)`. ```` Just like OR, the AND `&&` operator can sometimes replace `if`. @@ -303,3 +299,5 @@ There's a little more verbose way to do the same thing -- a built-in `Boolean` f alert( Boolean("non-empty string") ); // true alert( Boolean(null) ); // false ``` + +The precedence of NOT `!` is the highest of all bitwise operators, so it always executes first, before any `&&`, `||`.