File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
modules/45-logic/28-logical-negation Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,19 @@ theory: |
1616
1717 I.e., we can just put a `!` to the left of the function call and get the opposite result.
1818
19+ Negation works for any expression. Any value will be cast to the opposite boolean value.
20+
21+ ```javascript
22+ const message = 'Hello, world!';
23+ // Works with constants and variables
24+ !message; // false
25+
26+ // And directly with the values
27+ !5; // false
28+ !'hello'; // false
29+ !0; // true
30+ ```
31+
1932 Negation is a powerful tool that allows you to concisely express the desired rules in your code without having to write new functions.
2033
2134 What if you wrote `!!isEven(10)` like this? Suddenly, the code would work. Double negation in logic is equivalent to no negation at all.
@@ -26,6 +39,14 @@ theory: |
2639 !!isEven(10); // true
2740 ```
2841
42+ Negatives can be inside other expressions.
43+
44+ ```javascript
45+ true && !false; // true
46+ !false || false; // true
47+ !!isEven(10) && !'hello'; // false
48+ !!isEven(10) && !!'hello'; // true
49+
2950instructions : |
3051
3152 1. Write a function, `isPalindrome()`, to check if a word is a palindrome. A palindrome is a word that reads the same backwards as it does forwards.
Original file line number Diff line number Diff line change @@ -16,6 +16,19 @@ theory: |
1616
1717 То есть мы просто добавили `!` слева от вызова функции и получили обратное действие.
1818
19+ Отрицание работает для любых выражений. Любое значение будет приведено к противоположному значению логического типа.
20+
21+ ```javascript
22+ const message = 'Hello, world!';
23+ // Работает с константами и переменными
24+ !message; // false
25+
26+ // И напрямую со значениями
27+ !5; // false
28+ !'hello'; // false
29+ !0; // true
30+ ```
31+
1932 Отрицание — мощный инструмент, который позволяет лаконично выражать задуманные правила в коде без необходимости писать новые функции.
2033
2134 А что если написать так `!!isEven(10)`? Внезапно, но код сработает. В логике двойное отрицание подобно отсутствию отрицания вообще.
@@ -26,6 +39,15 @@ theory: |
2639 !!isEven(10); // true
2740 ```
2841
42+ Отрицания могут быть внутри других выражений.
43+
44+ ```javascript
45+ true && !false; // true
46+ !false || false; // true
47+ !!isEven(10) && !'hello'; // false
48+ !!isEven(10) && !!'hello'; // true
49+ ```
50+
2951instructions : |
3052
3153 В этом уроке вам нужно будет реализовать две функции `isPalindrome()` и `isNotPalindrome()`
You can’t perform that action at this time.
0 commit comments