1
00:00:00,360 --> 00:00:02,870
This lesson is all about comparison operators.

2
00:00:02,910 --> 00:00:07,680
We're going to look at Bulleen values, Truthy values, family values and a whole bunch of really neat

3
00:00:07,680 --> 00:00:08,010
things.

4
00:00:08,190 --> 00:00:15,450
So we did see earlier that we did use a comparison operator where we looked at the evaluation of content

5
00:00:15,450 --> 00:00:19,500
and seeing whether it's true or false when we are looking at booleans.

6
00:00:19,740 --> 00:00:25,800
So this is what a comparison operator does, is it allows us to ask a question and apply some logic

7
00:00:25,950 --> 00:00:32,370
so we can even do things like equal to which we've seen we can see greater than less than and these

8
00:00:32,370 --> 00:00:34,140
all return boolean values.

9
00:00:34,290 --> 00:00:38,300
So we're asking ourselves the question, is this comparable to that?

10
00:00:38,430 --> 00:00:42,450
And if it is, then we get a true value, and if not, then we get false.

11
00:00:42,480 --> 00:00:44,310
So they can only be one or the other.

12
00:00:44,320 --> 00:00:46,350
And those are where the booleans really shine.

13
00:00:46,590 --> 00:00:52,620
And also notice that when we do equal to that, we have two equal signs, sometimes three equal signs.

14
00:00:52,620 --> 00:00:54,390
If we're also including the data type.

15
00:00:54,540 --> 00:00:59,730
And this is important to note as when we're doing one equal sign, that's an assignment value.

16
00:00:59,750 --> 00:01:03,210
So that's an assignment operator and that's assigning a value.

17
00:01:03,210 --> 00:01:09,050
So to is to do the comparison so you can also use and combine and compare the two.

18
00:01:09,420 --> 00:01:12,270
So opening that up in the Mozilla developer network.

19
00:01:12,280 --> 00:01:18,300
So we've got all the different operators there and the assignment operators, their compound assignment

20
00:01:18,300 --> 00:01:19,980
operators that we've already seen.

21
00:01:20,100 --> 00:01:23,460
And then this is where we're looking at the comparison operators.

22
00:01:23,710 --> 00:01:29,160
So they're we've got the equal sign returns, too, if both are equal and they've got some examples

23
00:01:29,160 --> 00:01:29,390
here.

24
00:01:29,400 --> 00:01:35,070
So if three is equal to var one and if our one is actually three as well, that's good.

25
00:01:35,070 --> 00:01:35,430
Come back.

26
00:01:35,430 --> 00:01:36,990
True, otherwise it's false.

27
00:01:37,260 --> 00:01:42,750
We also have a not equal two, which is interesting because all you do is place the explanation mark

28
00:01:42,750 --> 00:01:43,680
plus the equals sign.

29
00:01:43,690 --> 00:01:47,270
So that also is looking for a true value.

30
00:01:47,280 --> 00:01:51,320
And if it's true, then it's going to run the first block a code within the condition.

31
00:01:51,630 --> 00:01:56,430
So that is something that if we've got three, not equal to four.

32
00:01:56,520 --> 00:01:57,860
And what's the answer to that?

33
00:01:57,870 --> 00:01:58,830
That's true.

34
00:01:59,040 --> 00:02:00,330
There's the strict equal.

35
00:02:00,360 --> 00:02:03,000
So this is also considering the data type.

36
00:02:03,210 --> 00:02:13,710
So meaning that if VAR is equal to the text, the string three and we've got a number three, then on

37
00:02:13,710 --> 00:02:16,080
those two equal sides, they are going to be equal.

38
00:02:16,080 --> 00:02:16,800
It's going to come back.

39
00:02:16,800 --> 00:02:17,240
True.

40
00:02:17,340 --> 00:02:20,250
But on the three equal signs, it's not going to come back.

41
00:02:20,250 --> 00:02:20,630
True.

42
00:02:20,650 --> 00:02:21,540
It's going to be false.

43
00:02:21,900 --> 00:02:28,110
And you can try all of this stuff out in the console so we could look at things like three equals three.

44
00:02:28,230 --> 00:02:29,610
And of course, that comes back.

45
00:02:29,610 --> 00:02:30,090
True.

46
00:02:30,240 --> 00:02:34,890
And if we do three equals and this is a string value that also comes back.

47
00:02:34,890 --> 00:02:35,280
True.

48
00:02:35,430 --> 00:02:39,630
And now if we try it with the third equal sine we see it comes back false.

49
00:02:39,930 --> 00:02:43,830
Three is not equal to and we do four.

50
00:02:43,950 --> 00:02:45,450
So that comes back true.

51
00:02:45,600 --> 00:02:50,190
And you could have some fun with this, play around with it, try out all the different values.

52
00:02:50,370 --> 00:02:52,260
So we see that that also returns back.

53
00:02:52,260 --> 00:02:52,590
True.

54
00:02:52,860 --> 00:02:56,730
And then within the statement then if we do return back true.

55
00:02:56,730 --> 00:02:58,530
Then that's when we run the function.

56
00:02:58,740 --> 00:03:00,390
You can also try different values.

57
00:03:00,390 --> 00:03:04,250
So you can say three is greater than six, which is false.

58
00:03:04,260 --> 00:03:09,270
We know that six is greater than three and that comes back true.

59
00:03:09,960 --> 00:03:15,570
70 is greater than or equal to 70 and that comes back true.

60
00:03:15,720 --> 00:03:18,560
So we know that 70 is not greater than true.

61
00:03:18,570 --> 00:03:19,710
So it comes back false.

62
00:03:19,980 --> 00:03:24,150
So there's a number of different combinations you can do and it really does take a little bit of time

63
00:03:24,150 --> 00:03:25,750
to get more familiar with these.

64
00:03:26,340 --> 00:03:30,750
This is where we've got the less than or equal to greater than or equal to.

65
00:03:30,900 --> 00:03:33,030
And they've got examples of how they work.

66
00:03:33,180 --> 00:03:36,960
If we're just doing the less than or greater than that, we only have the one simple there.

67
00:03:37,110 --> 00:03:43,420
We can also include the not so not within strict as well as not with an equal.

68
00:03:43,440 --> 00:03:48,240
So there's quite a few options and we can do a whole bunch of different types of comparisons.

69
00:03:48,630 --> 00:03:52,260
So what's being returned back is either a truthy or falsey.

70
00:03:52,590 --> 00:03:58,740
And we also saw this earlier when we were doing comparison between what boolean values, when we were

71
00:03:58,740 --> 00:03:59,640
adding them together.

72
00:03:59,650 --> 00:04:07,050
So we saw that booleans are either true or false and they could also be seen as a one or a zero and

73
00:04:07,050 --> 00:04:09,670
also values that are undefined.

74
00:04:09,690 --> 00:04:16,470
So if we have an undefined or a null or a zero or any NP being returned back for the variable, then

75
00:04:16,470 --> 00:04:18,300
that's going to come back as false.

76
00:04:18,660 --> 00:04:24,870
And otherwise, if we do have them and they are equal values, then they are true.

77
00:04:24,900 --> 00:04:26,610
So if it has a value, it's true.

78
00:04:26,790 --> 00:04:29,220
If it's set to true, it's true.

79
00:04:29,400 --> 00:04:31,710
And if it's got a value of one, then that's true.

80
00:04:31,740 --> 00:04:35,310
So those are the true things and the other ones were the falsies.

81
00:04:35,670 --> 00:04:41,940
So what we need to do in this challenge is check to see if a number exists and also check if it is greater

82
00:04:41,940 --> 00:04:42,500
than 50.

83
00:04:42,660 --> 00:04:44,400
So a message in the console.

84
00:04:44,410 --> 00:04:48,000
So first we're going to check to see if it exists for a variable.

85
00:04:48,000 --> 00:04:53,850
So get a variable, assign a value to it and do a condition checking to see if it's there and if it

86
00:04:53,850 --> 00:04:55,290
is output a message.

87
00:04:55,440 --> 00:04:58,830
And if there's no value, then we can do no doesn't exist.

88
00:04:58,840 --> 00:04:59,550
So use some of the.

89
00:04:59,650 --> 00:05:07,200
Falsies in order to indicate that it's not there, so null, zero false, et cetera, and then also

90
00:05:07,200 --> 00:05:10,290
check to see if the value is greater than 50.

91
00:05:10,290 --> 00:05:15,090
And if it is, then I'll put a message into the console so you can pause the video.

92
00:05:15,090 --> 00:05:17,420
And this is the solution to the challenge.

93
00:05:17,430 --> 00:05:21,870
So go ahead and pause the video and write up the solution within your editor.

94
00:05:21,870 --> 00:05:23,850
And I walk you through it coming up.

95
00:05:25,000 --> 00:05:25,720
Let's begin.

96
00:05:25,930 --> 00:05:32,740
So first of all, we need to have a number that we're going to be using so we can use five as our number

97
00:05:32,740 --> 00:05:37,900
that we're checking and we're going to check to see if none exists.

98
00:05:37,900 --> 00:05:43,460
And if it does, then we're going to run this blockquote and this is where we've got our console message.

99
00:05:43,630 --> 00:05:47,290
So if Chuck NUM exists, we can write check.

100
00:05:47,290 --> 00:05:50,020
None is true.

101
00:05:50,320 --> 00:05:57,580
So whatever it's returning back as true, then we get this message and next we want to also check to

102
00:05:57,580 --> 00:06:00,430
see if Chuck Numb is greater than 50.

103
00:06:00,970 --> 00:06:06,900
And I would put a message if it is greater than 50 and then we'll update the value of check number.

104
00:06:07,390 --> 00:06:11,210
And remember, it's even if it's 50, we're checking to see.

105
00:06:11,230 --> 00:06:12,910
So 50 is not greater than 50.

106
00:06:12,920 --> 00:06:14,090
So that's still going to be false.

107
00:06:14,350 --> 00:06:15,730
So keep that in mind as well.

108
00:06:16,120 --> 00:06:21,480
And then just to clarify what number we are working with will output in the consoles.

109
00:06:21,510 --> 00:06:26,620
We see that number is true and 55 and that's the number.

110
00:06:26,630 --> 00:06:28,630
So we're not seeing the bigger than 50.

111
00:06:28,840 --> 00:06:30,580
Let's try some of the other falsies.

112
00:06:30,940 --> 00:06:36,400
So set it to zero and we see that check number is not true.

113
00:06:36,400 --> 00:06:37,270
So it's not there.

114
00:06:37,270 --> 00:06:37,900
It's not true.

115
00:06:38,230 --> 00:06:43,590
And you can also add in an explanation, Mark, so that will negate that.

116
00:06:43,870 --> 00:06:48,090
So instead of being false, that will toggle it to be true.

117
00:06:48,550 --> 00:06:51,290
So it's a one little quick trick that you can do as well.

118
00:06:51,760 --> 00:06:57,430
So all of the ones that are null and undefined, it's always going to come back.

119
00:06:57,430 --> 00:06:59,770
And we're not seeing this message being output.

120
00:06:59,950 --> 00:07:02,490
So it's only until we have a value that's held in here.

121
00:07:02,740 --> 00:07:08,140
So even if we have a value of 500, you're going to see that that value is being output.

122
00:07:08,380 --> 00:07:15,340
And here's again, that type conversion where JavaScript is taking this string and it's saying, is

123
00:07:15,340 --> 00:07:19,300
that string larger than 50?

124
00:07:19,480 --> 00:07:22,650
And it's checking to see if it's trying to convert that string.

125
00:07:22,660 --> 00:07:27,850
So first thing it tries to do when it sees a string and tries to convert it in a number and if it works,

126
00:07:27,850 --> 00:07:28,960
then it's going to output it.

127
00:07:29,170 --> 00:07:35,940
But if you have something like test, then of course you can't check to see if test is larger than 50.

128
00:07:36,100 --> 00:07:40,030
So that's not going to come back and that's going to come back as a not a number.

129
00:07:40,150 --> 00:07:42,460
And remember, not a numbers are falsies.

130
00:07:42,640 --> 00:07:45,700
So that's why we're not seeing that output of that statement.

131
00:07:45,850 --> 00:07:54,300
And then lastly, for some bonus marks, check to see if the value of let's turn it back to five.

132
00:07:54,310 --> 00:07:56,140
So it's a string value of five.

133
00:07:56,530 --> 00:08:01,390
So we're going to check if check number is equal to five.

134
00:08:02,080 --> 00:08:04,270
And so what do you think is going to happen here?

135
00:08:04,420 --> 00:08:07,180
Do you think it's going to output that and we'll just put.

136
00:08:07,180 --> 00:08:07,780
Yes, there.

137
00:08:07,960 --> 00:08:09,460
So do you think yes.

138
00:08:09,460 --> 00:08:11,740
It's going to be output in the console or not?

139
00:08:12,220 --> 00:08:18,040
And remember that the three equal signs are different than the two equal signs because that's also looking

140
00:08:18,040 --> 00:08:18,920
for the data type.

141
00:08:19,300 --> 00:08:22,360
So when we have two equal signs, we see us.

142
00:08:22,570 --> 00:08:28,500
When we have three equal signs, we don't see us because that's not going to be a true statement.

143
00:08:28,990 --> 00:08:31,390
So try this out, have some fun with that experiment.

144
00:08:31,630 --> 00:08:34,750
And coming up next, more advanced with our conditions.
