1
00:00:02,040 --> 00:00:04,780
Now to play around with those operators,

2
00:00:04,780 --> 00:00:07,360
I'm back here in the console,

3
00:00:07,360 --> 00:00:10,150
this JavaScript console and the dev tools.

4
00:00:10,150 --> 00:00:13,660
Since we can quickly enter a code like this here

5
00:00:13,660 --> 00:00:15,940
and instantly see the result,

6
00:00:15,940 --> 00:00:18,647
which is more convenient than typing it here

7
00:00:18,647 --> 00:00:21,630
and then executing the code and then seeing it here.

8
00:00:21,630 --> 00:00:23,950
So that's why we'll continue here.

9
00:00:23,950 --> 00:00:26,960
And let's play around with those various operators

10
00:00:26,960 --> 00:00:28,340
I showed you.

11
00:00:28,340 --> 00:00:29,860
And for example, you see,

12
00:00:29,860 --> 00:00:33,220
we can compare numbers with each other for equality.

13
00:00:33,220 --> 00:00:34,290
And I did mention

14
00:00:34,290 --> 00:00:37,990
that we have two kinds of equality operators there

15
00:00:37,990 --> 00:00:41,470
with two and with free equal signs.

16
00:00:41,470 --> 00:00:42,820
Now, what's the difference?

17
00:00:43,710 --> 00:00:44,950
The difference is that

18
00:00:44,950 --> 00:00:48,390
if you use the one with two equal signs,

19
00:00:48,390 --> 00:00:51,320
you compare devalues only.

20
00:00:51,320 --> 00:00:55,130
And as a consequence, if you would compare to number five

21
00:00:55,130 --> 00:00:59,440
with the string five, with the two equal sign operator,

22
00:00:59,440 --> 00:01:01,330
you would get true.

23
00:01:01,330 --> 00:01:03,810
With the triple equal sign operator,

24
00:01:03,810 --> 00:01:07,240
you instead, also the check for type equality.

25
00:01:07,240 --> 00:01:10,550
So for this comparison, you get false

26
00:01:10,550 --> 00:01:13,730
because whilst the value is to same five,

27
00:01:13,730 --> 00:01:16,010
the value type is not the same.

28
00:01:16,010 --> 00:01:18,510
One of them is a number and one of them is a string

29
00:01:18,510 --> 00:01:21,593
and these are different value types as you learned.

30
00:01:22,620 --> 00:01:26,860
And therefore it is generally considered a best practice

31
00:01:26,860 --> 00:01:30,290
to always use to triple equal sign operator,

32
00:01:30,290 --> 00:01:35,290
because typically you should compare equal types.

33
00:01:35,340 --> 00:01:36,360
Of course, if you know

34
00:01:36,360 --> 00:01:39,040
that you need to compare a string to a number

35
00:01:39,040 --> 00:01:41,370
and you want to check for value only

36
00:01:41,370 --> 00:01:45,133
it is fine to use the double equal sign operator as well.

37
00:01:46,840 --> 00:01:49,320
Now, we also learned about the negation operator

38
00:01:49,320 --> 00:01:52,540
and there we could check if five is not equal to five,

39
00:01:52,540 --> 00:01:55,680
which of course is false because they are equal.

40
00:01:55,680 --> 00:01:59,010
And for example, checking a four is not equal to five

41
00:01:59,010 --> 00:02:01,400
therefore would yield true.

42
00:02:01,400 --> 00:02:05,570
And here we would also actually get true.

43
00:02:05,570 --> 00:02:08,550
If I check for five, not being equal to five,

44
00:02:08,550 --> 00:02:10,059
if the second five is a string

45
00:02:10,059 --> 00:02:12,860
and the first one is a number.

46
00:02:12,860 --> 00:02:16,380
So that's how we could use this negation operator.

47
00:02:16,380 --> 00:02:20,250
It also exists on a one equal sign only though.,

48
00:02:20,250 --> 00:02:22,860
and then here I would get false because now again,

49
00:02:22,860 --> 00:02:25,063
we only have a look at the value.

50
00:02:26,730 --> 00:02:29,800
Now, besides equality or not equality,

51
00:02:29,800 --> 00:02:34,750
we can also check for values being greater or smaller.

52
00:02:34,750 --> 00:02:38,270
And for example, we can check if three is greater than one,

53
00:02:38,270 --> 00:02:42,720
and if four is greater than six, which of course is not,

54
00:02:42,720 --> 00:02:45,980
we can check for 'a' being greater than 'b',

55
00:02:45,980 --> 00:02:50,570
which is not because 'b' comes after 'a' in the alphabet.

56
00:02:50,570 --> 00:02:55,570
And we can check if 'cb' is greater than 'ab', which it is

57
00:02:55,580 --> 00:02:58,890
because if you have multiple characters in the string,

58
00:02:58,890 --> 00:03:02,460
the characters are compared character by character.

59
00:03:02,460 --> 00:03:05,160
So first 'c' and 'a' is compared

60
00:03:05,160 --> 00:03:08,410
and if we have a winner there, then we're done.

61
00:03:08,410 --> 00:03:10,190
And only if they would be equal,

62
00:03:10,190 --> 00:03:12,370
it would move on to the second character

63
00:03:12,370 --> 00:03:14,600
and compare those with each other.

64
00:03:14,600 --> 00:03:16,560
But here 'c' is greater than 'a',

65
00:03:16,560 --> 00:03:19,723
and that's why we overall it gets true for this comparison.

66
00:03:20,570 --> 00:03:25,570
And we can also check for equality so greater or equal

67
00:03:25,610 --> 00:03:27,270
and that would also behave

68
00:03:27,270 --> 00:03:30,173
just as you would probably expect it.

69
00:03:31,520 --> 00:03:32,840
Now it is worth mentioning

70
00:03:32,840 --> 00:03:35,960
that you can't combine the negation operator

71
00:03:35,960 --> 00:03:39,050
with those kinds of comparisons just like this.

72
00:03:39,050 --> 00:03:42,580
So you can't do that.

73
00:03:42,580 --> 00:03:44,000
You see, you get an error.

74
00:03:44,000 --> 00:03:48,320
Instead here, you would first execute this comparison,

75
00:03:48,320 --> 00:03:49,980
wrap ii in brackets,

76
00:03:49,980 --> 00:03:53,000
and then add your negation operator in front of it

77
00:03:53,000 --> 00:03:56,150
because you can always use this negotiation operator

78
00:03:56,150 --> 00:04:01,150
to convert a true value to false or a false value to true.

79
00:04:01,150 --> 00:04:02,850
And that's essentially what we're doing here.

80
00:04:02,850 --> 00:04:06,530
Then we are first deriving a true or false value,

81
00:04:06,530 --> 00:04:09,183
and then we're getting the inverse of it.

82
00:04:10,770 --> 00:04:14,350
Now that we're are comparison operators,

83
00:04:14,350 --> 00:04:16,750
we also got the logical operators.

84
00:04:16,750 --> 00:04:19,850
And here we got and, and, or.

85
00:04:19,850 --> 00:04:21,450
And here, the idea is simply that

86
00:04:21,450 --> 00:04:24,850
sometimes we have multiple combined conditions.

87
00:04:24,850 --> 00:04:28,200
For example, we could be checking if five is equal to five,

88
00:04:28,200 --> 00:04:30,763
and if three is equal to three,

89
00:04:31,810 --> 00:04:33,100
and that would return true

90
00:04:33,100 --> 00:04:37,023
because both individual expressions here yield true.

91
00:04:38,400 --> 00:04:43,400
If we would have at least one expression that yields false,

92
00:04:44,460 --> 00:04:46,980
the overall expression would yield false

93
00:04:46,980 --> 00:04:49,393
with that end operator.

94
00:04:50,410 --> 00:04:52,653
With the or operator on the other hand,

95
00:04:52,653 --> 00:04:56,440
that is enough if at least one of the two expressions

96
00:04:56,440 --> 00:04:57,620
yields true.

97
00:04:57,620 --> 00:05:00,960
So there, if we had basically the same line of code,

98
00:05:00,960 --> 00:05:04,200
but with the, or operator, we would get true now

99
00:05:04,200 --> 00:05:06,713
because at least one of the two yields, true.

100
00:05:07,730 --> 00:05:10,400
Of course, if both yield false,

101
00:05:10,400 --> 00:05:12,900
for example, if I changed this five to a six,

102
00:05:12,900 --> 00:05:17,100
then we would also get back false as an overall result here.

103
00:05:17,100 --> 00:05:18,720
Now it's also worth mentioning

104
00:05:18,720 --> 00:05:23,190
that you can combine as many comparisons as you want.

105
00:05:23,190 --> 00:05:24,700
For example, we could be saying

106
00:05:24,700 --> 00:05:27,200
that we wanna check if two is equal to two,

107
00:05:27,200 --> 00:05:29,870
or if two is equal to three,

108
00:05:29,870 --> 00:05:34,283
and we wanna check if five is equal to six.

109
00:05:35,290 --> 00:05:37,710
And what you see is that if I would execute this,

110
00:05:37,710 --> 00:05:38,740
it would work.

111
00:05:38,740 --> 00:05:41,630
And I would get true as an overall result

112
00:05:41,630 --> 00:05:43,330
because by default,

113
00:05:43,330 --> 00:05:47,010
this will be evaluated or read like this.

114
00:05:47,010 --> 00:05:50,280
JavaScript will first evaluate this part

115
00:05:50,280 --> 00:05:52,660
with the end operator,

116
00:05:52,660 --> 00:05:57,420
since this has higher priority in JavaScript

117
00:05:57,420 --> 00:06:01,330
and therefore the result of this comparison will be false

118
00:06:01,330 --> 00:06:05,820
because both conditions here actually yield false,

119
00:06:05,820 --> 00:06:09,130
but even if just one of them would yield false,

120
00:06:09,130 --> 00:06:11,740
this would still overall yield false

121
00:06:11,740 --> 00:06:15,220
because that's how the end operator works.

122
00:06:15,220 --> 00:06:18,350
But then you see that the overall result is true,

123
00:06:18,350 --> 00:06:21,160
and that tells us that JavaScript then

124
00:06:21,160 --> 00:06:24,470
takes the result of this second comparison here

125
00:06:24,470 --> 00:06:25,960
with the end operator

126
00:06:25,960 --> 00:06:29,810
and of course combined stays with the first comparison here

127
00:06:29,810 --> 00:06:32,020
with the or operator.

128
00:06:32,020 --> 00:06:35,660
And you learned that the effort is overall will yield true

129
00:06:35,660 --> 00:06:38,150
if at least one of the two operations

130
00:06:38,150 --> 00:06:42,200
that are compared with that or operator yield true.

131
00:06:42,200 --> 00:06:43,033
And that's the case,

132
00:06:43,033 --> 00:06:45,853
because this first operation yields true.

133
00:06:46,900 --> 00:06:49,500
Now, just like in regular moth,

134
00:06:49,500 --> 00:06:54,500
you can override is built in priority by adding parentheses.

135
00:06:54,820 --> 00:06:58,830
If you wanna say that you don't want this second part here

136
00:06:58,830 --> 00:07:00,840
to be evaluated first,

137
00:07:00,840 --> 00:07:04,590
but instead you first wanna check this or operation

138
00:07:04,590 --> 00:07:05,930
and then combine that

139
00:07:05,930 --> 00:07:08,770
with the result of this last comparison,

140
00:07:08,770 --> 00:07:12,063
you can do this by simply adding parentheses here.

141
00:07:12,930 --> 00:07:16,020
Now you see, we overall get false

142
00:07:16,020 --> 00:07:19,090
because now JavaScript will first of all,

143
00:07:19,090 --> 00:07:23,530
make this evaluation here and that of course yields true

144
00:07:23,530 --> 00:07:27,270
because well, both sides have or return true,

145
00:07:27,270 --> 00:07:28,700
but it would even be enough

146
00:07:28,700 --> 00:07:31,900
if just one of them would yield true.

147
00:07:31,900 --> 00:07:36,000
But then the overall result of this first comparison

148
00:07:36,000 --> 00:07:38,370
of this first evaluation here

149
00:07:38,370 --> 00:07:42,590
is combined with that last comparison with the end operator

150
00:07:42,590 --> 00:07:44,840
and therefore we overall get false

151
00:07:44,840 --> 00:07:49,630
because this yields false, five is not equal to six.

152
00:07:49,630 --> 00:07:51,390
And you learned that for 'n',

153
00:07:51,390 --> 00:07:55,500
both sides need to yield true and that's not the case here,

154
00:07:55,500 --> 00:07:56,933
hence we get false.

155
00:07:57,970 --> 00:08:01,300
So you can combine as many comparisons as you want

156
00:08:01,300 --> 00:08:04,050
and you now also learned about the priority

157
00:08:04,050 --> 00:08:06,210
of the different operators.

158
00:08:06,210 --> 00:08:09,850
And that said four days introduction to booleans

159
00:08:09,850 --> 00:08:12,903
and this comparison of logical operators.

160
00:08:13,840 --> 00:08:16,420
Of course, playing around with numbers

161
00:08:16,420 --> 00:08:18,160
in the console like this,

162
00:08:18,160 --> 00:08:20,970
is not what we would do in real apps,

163
00:08:20,970 --> 00:08:24,560
but it is useful to understand these operators.

164
00:08:24,560 --> 00:08:26,940
I'm just giving you this overview right now,

165
00:08:26,940 --> 00:08:29,250
so that we can then use all these features

166
00:08:29,250 --> 00:08:30,890
later throughout the course.

167
00:08:30,890 --> 00:08:33,120
But of course, there, you will then also see them

168
00:08:33,120 --> 00:08:35,602
in more realistic scenarios.

169
00:08:36,480 --> 00:08:37,750
For example,

170
00:08:37,750 --> 00:08:41,423
back here in this example code I started with earlier.

