1
00:00:02,170 --> 00:00:07,170
If statements need Boolean values between those brackets

2
00:00:07,960 --> 00:00:12,960
and we also called those values just booleans

3
00:00:13,140 --> 00:00:16,546
and that's another value type besides strings

4
00:00:16,546 --> 00:00:20,060
and numbers and objects and arrays,

5
00:00:20,060 --> 00:00:22,930
Boolean values are a special value type

6
00:00:22,930 --> 00:00:27,930
that have exactly two possible values, true or false.

7
00:00:28,680 --> 00:00:31,030
So it's like yes or no, just to that,

8
00:00:31,030 --> 00:00:33,410
it's called true and false.

9
00:00:33,410 --> 00:00:36,690
And these two values are our Boolean values,

10
00:00:36,690 --> 00:00:39,393
we can work with in JavaScript.

11
00:00:40,240 --> 00:00:42,780
So whereas a number can be any number

12
00:00:42,780 --> 00:00:44,720
and a string can hold any texts.

13
00:00:44,720 --> 00:00:48,890
A Boolean value can only hold either true or false.

14
00:00:48,890 --> 00:00:51,550
And these are useful, these values,

15
00:00:51,550 --> 00:00:54,920
if we have a yes or no question.

16
00:00:54,920 --> 00:00:57,315
And when do we have such a question?

17
00:00:57,315 --> 00:01:01,800
Exactly. If we have an "if statement",

18
00:01:01,800 --> 00:01:04,670
because we want to execute some code,

19
00:01:04,670 --> 00:01:09,670
to code inside of these curly braces in this if statement,

20
00:01:09,860 --> 00:01:14,860
if a certain condition is met. So if this year says, yes,

21
00:01:15,000 --> 00:01:17,950
then we want to execute the code. If it says no,

22
00:01:17,950 --> 00:01:20,610
so falls in the Boolean world,

23
00:01:20,610 --> 00:01:22,563
then we don't want to execute this.

24
00:01:23,450 --> 00:01:26,080
Now we could directly add true here

25
00:01:26,080 --> 00:01:29,110
as a value and very important

26
00:01:29,110 --> 00:01:32,580
Here we don't have quotes because,

27
00:01:32,580 --> 00:01:34,574
we don't want a string like this instead,

28
00:01:34,574 --> 00:01:38,100
true and false are values,

29
00:01:38,100 --> 00:01:41,530
which are built in as keywords like this.

30
00:01:41,530 --> 00:01:45,563
And if I would set this to true then this would execute.

31
00:01:46,450 --> 00:01:48,287
If I now a save that code

32
00:01:48,287 --> 00:01:52,730
and I open my console here, we see how low.

33
00:01:52,730 --> 00:01:53,820
And on the other hand,

34
00:01:53,820 --> 00:01:57,851
if I set this to false and I saved this,

35
00:01:57,851 --> 00:02:02,851
then we don't see anything. Because then, that code in the,

36
00:02:03,002 --> 00:02:05,350
if statement does not execute,

37
00:02:05,350 --> 00:02:07,930
because that does not answer the question,

38
00:02:07,930 --> 00:02:09,880
wherever that code would be executed.

39
00:02:09,880 --> 00:02:14,030
So if that code would be executed with true instead,

40
00:02:14,030 --> 00:02:16,883
it answers it with false, which means no.

41
00:02:18,080 --> 00:02:21,030
So if false then do nothing.

42
00:02:21,030 --> 00:02:24,350
If true, then execute this code.

43
00:02:24,350 --> 00:02:25,993
This is how you can read this.

44
00:02:26,860 --> 00:02:31,240
Now boolean values are super important in programming

45
00:02:31,240 --> 00:02:34,860
because we need them for control structures like this,

46
00:02:34,860 --> 00:02:37,830
because we need them for "if statements".

47
00:02:37,830 --> 00:02:41,380
And as you will see in most programs that you write,

48
00:02:41,380 --> 00:02:44,020
you will have some parts of your code

49
00:02:44,020 --> 00:02:46,310
that are actually conditional,

50
00:02:46,310 --> 00:02:49,500
that need "if statements" so that you can control

51
00:02:49,500 --> 00:02:53,460
which code should run, and if it should run at all,

52
00:02:53,460 --> 00:02:55,070
but you will typically not.

53
00:02:55,070 --> 00:02:59,290
Hard-code true or false into your if statement as we are

54
00:02:59,290 --> 00:03:02,140
currently doing it, why not?

55
00:03:02,140 --> 00:03:04,960
Well, because then the entire if statement is redundant.

56
00:03:04,960 --> 00:03:08,170
This will always be true, and this will always be false.

57
00:03:08,170 --> 00:03:10,860
So that's not too useful.

58
00:03:10,860 --> 00:03:14,910
I only did that to introduce Boolean values

59
00:03:14,910 --> 00:03:18,797
In stat, you will typically derive Boolean values

60
00:03:18,797 --> 00:03:22,774
with help of so-called comparison operators

61
00:03:22,774 --> 00:03:27,130
and also sometimes with logical operators.

62
00:03:27,130 --> 00:03:30,363
And I will, of course explain both types of operators.

63
00:03:31,330 --> 00:03:35,168
Up to this point, we did learn about those moth operators

64
00:03:35,168 --> 00:03:38,554
and the concatenation operator does plus,

65
00:03:38,554 --> 00:03:40,380
which we can use on strings

66
00:03:41,300 --> 00:03:43,720
comparison and logical operators

67
00:03:43,720 --> 00:03:46,850
are additional sets of operators,

68
00:03:46,850 --> 00:03:49,363
which we can use in Java script.

69
00:03:50,340 --> 00:03:54,910
But the whereas mathematical operators yield us numbers

70
00:03:54,910 --> 00:03:59,550
and the concatenation operator returns a string comparison

71
00:03:59,550 --> 00:04:04,550
and logical operators will actually give us Boolean values.

72
00:04:04,763 --> 00:04:08,520
And let's start with comparison operators here.

73
00:04:08,520 --> 00:04:10,930
Here, we got these operators,

74
00:04:10,930 --> 00:04:15,523
which we can use to compare values with each other.

75
00:04:17,089 --> 00:04:21,920
The first set of operators here is the equality operator

76
00:04:21,920 --> 00:04:24,850
and there we have two kinds of equality operators

77
00:04:24,850 --> 00:04:27,620
with two and three equal signs.

78
00:04:27,620 --> 00:04:30,110
And I'll show you the difference in a second,

79
00:04:30,110 --> 00:04:33,130
but basically we use these operators

80
00:04:33,130 --> 00:04:37,210
if we want to compare two values for equality.

81
00:04:37,210 --> 00:04:38,410
So for example,

82
00:04:38,410 --> 00:04:41,480
if we would want to check whether two is equal to two

83
00:04:42,796 --> 00:04:44,968
or two as a string, as equal to two,

84
00:04:44,968 --> 00:04:46,340
and you see that would actually give us false

85
00:04:46,340 --> 00:04:49,120
if we use that triple equals on operator.

86
00:04:49,120 --> 00:04:52,430
But again, I will explain it in greater detail soon.

87
00:04:52,430 --> 00:04:54,469
And you'll see a couple of other

88
00:04:54,469 --> 00:04:56,310
examples down there as well.

89
00:04:56,310 --> 00:04:59,510
This equality operator can be used to compare

90
00:04:59,510 --> 00:05:02,460
numbers with numbers, strings with strings,

91
00:05:02,460 --> 00:05:06,957
numbers with strings and a couple of other values as well.

92
00:05:06,957 --> 00:05:10,020
It also has a couple of gotchas, but again,

93
00:05:10,020 --> 00:05:12,230
we will see that through out the course.

94
00:05:12,230 --> 00:05:15,270
And in general, the deeper you dive into JavaScript,

95
00:05:15,270 --> 00:05:17,720
the more you will learn about those gotchas,

96
00:05:17,720 --> 00:05:20,560
but it generally works quite straightforward.

97
00:05:20,560 --> 00:05:23,780
You can use it to compare values for equality.

98
00:05:23,780 --> 00:05:26,670
And of course the examples here,

99
00:05:26,670 --> 00:05:30,380
I have hard-coded values only in reality,

100
00:05:30,380 --> 00:05:34,340
you would typically compare values that are entered

101
00:05:34,340 --> 00:05:36,290
by a user in some input field,

102
00:05:36,290 --> 00:05:40,301
from what you've got the value or what you fetched

103
00:05:40,301 --> 00:05:42,270
from some website or anything like that.

104
00:05:42,270 --> 00:05:45,130
Because otherwise, of course, if you hard code the values,

105
00:05:45,130 --> 00:05:48,300
you already know the answer in advance as a developer.

106
00:05:48,300 --> 00:05:50,443
These are really just examples here.

107
00:05:52,320 --> 00:05:54,751
Now the next set of comparison operators are these

108
00:05:54,751 --> 00:05:57,990
greater than, lesser than,

109
00:05:57,990 --> 00:06:01,960
greater or equal and lesser or equal operators,

110
00:06:01,960 --> 00:06:06,060
which allow you to do these exact operations where you

111
00:06:06,060 --> 00:06:08,852
can check whether five is greater than three and so on.

112
00:06:08,852 --> 00:06:13,120
It is worth pointing out that you can also use these

113
00:06:13,120 --> 00:06:16,960
operators on strings. And they're A would for example,

114
00:06:16,960 --> 00:06:21,800
be smaller than B because it comes earlier in the alphabet.

115
00:06:21,800 --> 00:06:24,490
So that's all the worth mentioning here.

116
00:06:24,490 --> 00:06:27,090
Now, the last set of comparison operators,

117
00:06:27,090 --> 00:06:30,550
which you see here are negation operators

118
00:06:30,550 --> 00:06:34,870
or operators that yield the inverse of what you're checking.

119
00:06:34,870 --> 00:06:37,590
So you can check if something is not true.

120
00:06:37,590 --> 00:06:40,090
And you'll see a couple of examples here.

121
00:06:40,090 --> 00:06:41,940
Please note that in the first line,

122
00:06:41,940 --> 00:06:45,230
I'm also using brackets so that for smaller,

123
00:06:45,230 --> 00:06:48,530
four is evaluated first and that would

124
00:06:48,530 --> 00:06:53,470
normally yield false because four is not smaller than four,

125
00:06:53,470 --> 00:06:55,720
but with the negation operator,

126
00:06:55,720 --> 00:06:59,710
the exclamation mark here I then get the inverse of bet.

127
00:06:59,710 --> 00:07:02,350
And the inverse of false is true.

128
00:07:02,350 --> 00:07:05,100
And that's how we derive that value.

129
00:07:05,100 --> 00:07:07,873
And that's also sometimes exactly what you need.

130
00:07:08,740 --> 00:07:11,660
Now, Sometimes you don't just have one check that

131
00:07:11,660 --> 00:07:14,660
you want to perform, but multiple checks.

132
00:07:14,660 --> 00:07:15,493
And then it's the overall result of combining

133
00:07:15,493 --> 00:07:19,610
all those checks and they have for combining

134
00:07:19,610 --> 00:07:23,450
all those Boolean values, which result from these checks.

135
00:07:23,450 --> 00:07:26,740
And that's exactly where logical operators can help you

136
00:07:27,630 --> 00:07:30,890
Here, we got two kinds of logical operators.

137
00:07:30,890 --> 00:07:35,190
We got the and and or operator and with,

138
00:07:35,190 --> 00:07:39,562
and we get true if both compared values are true

139
00:07:39,562 --> 00:07:41,637
and here are some examples

140
00:07:41,637 --> 00:07:43,880
for how that would behave

141
00:07:45,210 --> 00:07:47,836
and with the, or operator we get true.

142
00:07:47,836 --> 00:07:51,515
If one of the two values is true.

143
00:07:51,515 --> 00:07:52,650
So here it's enough.

144
00:07:52,650 --> 00:07:56,490
If one of them is true and you'll see some examples here,

145
00:07:56,490 --> 00:07:59,370
basically the same examples as on the left, just with,

146
00:07:59,370 --> 00:08:03,260
or instead of, and, and that's of course,

147
00:08:03,260 --> 00:08:05,230
just an overview and a summary.

148
00:08:05,230 --> 00:08:09,430
We are now going to explore these operators and play around

149
00:08:09,430 --> 00:08:13,580
with them in code and then see how we can use them in

150
00:08:13,580 --> 00:08:15,690
conjunction with if statements

151
00:08:15,690 --> 00:08:17,680
to do more useful things there

