1
00:00:00,395 --> 00:00:02,817
A lot of times in if statements we need to

2
00:00:02,817 --> 00:00:05,361
do some comparisons, so we have all the

3
00:00:05,361 --> 00:00:07,621
standard ones you'd come to expect in any

4
00:00:07,621 --> 00:00:10,393
language. We have less than, we have less

5
00:00:10,393 --> 00:00:14,122
than or equal to, we have greater than, we

6
00:00:14,122 --> 00:00:17,395
have greater than or equal to, we have

7
00:00:17,395 --> 00:00:21,143
equal in value, and we also have equal in

8
00:00:21,143 --> 00:00:23,738
value and type, and this is the one you

9
00:00:23,738 --> 00:00:26,475
should use most often when you want to

10
00:00:26,475 --> 00:00:30,640
actually do real comparisons, so it's ===.

11
00:00:30,640 --> 00:00:33,859
We have not equal in value, and we have

12
00:00:33,859 --> 00:00:38,921
not equal in value and in type. So let's

13
00:00:38,921 --> 00:00:42,362
go ahead and take a look at these various

14
00:00:42,362 --> 00:00:47,125
comparison operators. We have a function

15
00:00:47,125 --> 00:00:49,262
called comparisonSample, where I've set

16
00:00:49,262 --> 00:00:51,980
the price = 200. And then what we're going

17
00:00:51,980 --> 00:00:53,948
to take a look at are all the various ways

18
00:00:53,948 --> 00:00:55,965
that we can do a comparison. So on line

19
00:00:55,965 --> 00:00:58,442
21, we're going to actually check to see

20
00:00:58,442 --> 00:01:01,661
if price is double equal price. And of

21
00:01:01,661 --> 00:01:04,229
course that should come out to be true.

22
00:01:04,229 --> 00:01:07,521
But then look at the line 24. I'm going to

23
00:01:07,521 --> 00:01:10,274
set result now equal to price.toString. So

24
00:01:10,274 --> 00:01:14,157
I'm changing price to a string. When we

25
00:01:14,157 --> 00:01:16,413
use the double equals to compare the

26
00:01:16,413 --> 00:01:19,543
price, which is a number, to the result,

27
00:01:19,543 --> 00:01:22,608
which is a string, this one should come

28
00:01:22,608 --> 00:01:24,676
out true because we're using double

29
00:01:24,676 --> 00:01:26,855
equals, which just simply checks for

30
00:01:26,855 --> 00:01:29,938
value. So what it does is, it looks inside

31
00:01:29,938 --> 00:01:32,000
and figures out if that string can

32
00:01:32,000 --> 00:01:34,621
actually be converted to a numeric, and

33
00:01:34,621 --> 00:01:37,287
then performs the comparison. Now let's

34
00:01:37,287 --> 00:01:41,121
take a look at the next one where I set

35
00:01:41,121 --> 00:01:44,332
result equal to price. So what happens is,

36
00:01:44,332 --> 00:01:46,781
now when I'm using triple equals, it's

37
00:01:46,781 --> 00:01:50,912
saying, is price and result the same data

38
00:01:50,912 --> 00:01:54,399
type and the same value? That should come

39
00:01:54,399 --> 00:01:57,150
out to be true. But then look at the next

40
00:01:57,150 --> 00:02:00,806
one on line 32 where I again set result

41
00:02:00,806 --> 00:02:03,117
equal to price.toString. So now we're

42
00:02:03,117 --> 00:02:05,223
comparing a price, which is a numeric, to

43
00:02:05,223 --> 00:02:08,289
a result, which is a string, and we're

44
00:02:08,289 --> 00:02:11,404
using triple equals, which means the value

45
00:02:11,404 --> 00:02:14,779
part, yes, that's true, but the data type

46
00:02:14,779 --> 00:02:18,696
is not. So that one's going to report a

47
00:02:18,696 --> 00:02:21,071
false. We then have the same thing for not

48
00:02:21,071 --> 00:02:25,249
equal. So on the not equal, we can do an!

49
00:02:25,249 --> 00:02:28,159
=, and it'll check the value, or we can do

50
00:02:28,159 --> 00:02:32,481
an! ==, so that gives us the three, just

51
00:02:32,481 --> 00:02:34,668
like the three equals signs, but we're

52
00:02:34,668 --> 00:02:36,849
using an exclamation point for the not, so

53
00:02:36,849 --> 00:02:39,816
if they're not equal in type and value.

54
00:02:39,816 --> 00:02:42,694
And of course we have all the rest of

55
00:02:42,694 --> 00:02:44,643
them, greater, greater than or equal to,

56
00:02:44,643 --> 00:02:47,258
less than, less than or equal to. and then

57
00:02:47,258 --> 00:02:49,398
of course we have the ternary operator as

58
00:02:49,398 --> 00:02:52,799
well. What this says is that the first

59
00:02:52,799 --> 00:02:56,064
part of this expression, which, in this

60
00:02:56,064 --> 00:02:59,385
case, is price, less than 1500. Question

61
00:02:59,385 --> 00:03:02,839
mark means take the next piece between the

62
00:03:02,839 --> 00:03:05,517
question mark and the colon, and report

63
00:03:05,517 --> 00:03:08,609
that back. the colon says, this is like

64
00:03:08,609 --> 00:03:11,090
the else portion, so if price is greater

65
00:03:11,090 --> 00:03:14,022
than or equal to 1500, then this part

66
00:03:14,022 --> 00:03:17,402
would be spit out, which would be greater

67
00:03:17,402 --> 00:03:21,453
than 1500. Let's go ahead and run this.

68
00:03:21,453 --> 00:03:24,031
And we can then see the results, which are

69
00:03:24,031 --> 00:03:27,000
the same as what we discussed when we were looking at the code.

