WEBVTT

00:03.530 --> 00:06.890
In previous video, we have talked about arithmetical operators.

00:07.310 --> 00:11.510
Now it's time to consider a different type of operators, which are a comparison.

00:12.660 --> 00:16.200
So what are prison operators and what they are used for?

00:17.070 --> 00:23.520
Component operators are used in logical statements to determine equality or difference between variables

00:23.520 --> 00:28.860
or values, so they are used to test for true or false, which are boolean values.

00:28.860 --> 00:34.860
As you remember in JavaScript, you will meet very frequently these situations where you have to either

00:34.860 --> 00:39.710
make decisions or choose something, compare values to each other and so on.

00:40.320 --> 00:44.490
For that, you should really understand how comparison operators actually work.

00:46.030 --> 00:48.820
All right, let's create variables.

00:51.250 --> 00:55.690
Verbal and B and I sign both of them five.

00:57.040 --> 01:03.670
As you remember from previous videos, equals sign is used to assign the values to variables, it doesn't

01:03.670 --> 01:06.110
mean equality, it just assigns the value.

01:06.670 --> 01:09.160
So it's called as assignment operator.

01:10.330 --> 01:17.050
In order to compare the equality of those variables, we can use double equals operator, which compares

01:17.050 --> 01:19.950
the values, but it doesn't compare the type of the values.

01:20.770 --> 01:25.000
So I will show you now what exactly means I'm going to work in cons..

01:25.000 --> 01:27.710
For now, you can test your anything you want.

01:27.730 --> 01:32.440
That's why I've told you that Consultive is grateful for JavaScript developers, so.

01:32.440 --> 01:32.800
Right.

01:32.800 --> 01:34.990
A double equals to be.

01:36.660 --> 01:39.360
It's obviously true because the values are the same.

01:40.260 --> 01:45.900
Now let's change the type of one of the values and write it as a string.

01:48.410 --> 01:53.570
It's also true because, as we said, this type of comparison operator doesn't compare the types of

01:53.570 --> 02:00.680
the values and it also cause the types what I mean, in type corrosion, I will show you it's a bit

02:00.680 --> 02:01.170
later.

02:02.360 --> 02:09.320
So using double equals operator seems maybe nice, but it's not actually safe because it may cause unexpected

02:09.320 --> 02:10.300
bugs and errors.

02:10.760 --> 02:18.380
Therefore, we need something else like strict mold and it's triple equals, which compares not only

02:18.380 --> 02:21.190
values but also the types.

02:21.830 --> 02:23.270
Let's prove this right.

02:23.270 --> 02:24.980
A triple equals to be.

02:26.410 --> 02:33.550
You see that it's false because types of the values are different, the data type of variable A is no

02:34.030 --> 02:35.460
and B is a string.

02:36.340 --> 02:43.090
So I recommend you to use a equals comparison operator in practice because it's safer than double equals.

02:43.690 --> 02:44.200
All right.

02:44.530 --> 02:47.410
Let's go ahead and talk about other comparison operators.

02:47.860 --> 02:49.720
Double equals and triple equals.

02:49.720 --> 02:56.080
Operators have opposite ones, not equals and strict not equals, which are written with exclamation

02:56.080 --> 02:56.470
marks.

02:56.920 --> 03:01.730
And they work in the exact same way as the previous ones, but they give us opposite values.

03:02.740 --> 03:11.480
So when A double equals B was true, then A not equals to B is false because it's opposite.

03:12.310 --> 03:15.340
So remember, when double equals gives us for example.

03:15.340 --> 03:18.960
True, they're not equals, gives us false and vice versa.

03:20.100 --> 03:25.380
The same is happening with equals and strict not equals if we write a.

03:26.390 --> 03:28.790
Strict not equals to be.

03:30.350 --> 03:32.000
Then we will get through.

03:34.240 --> 03:41.230
All right, you can find all of these operators, Operator Precedent's table, they have same this number

03:41.410 --> 03:41.890
10.

03:42.920 --> 03:50.480
You can find also other component operators, such as less than less than or equal, greater than and

03:50.480 --> 03:56.510
greater than or equal, although the operators act as simply as you know it from your math class.

03:57.460 --> 04:00.190
They have higher precedence number and it's 11.

04:01.420 --> 04:07.780
As for assignment operator, which is an equal sign, it has the lower precedence number that the comparison

04:07.780 --> 04:09.300
operators and it's three.

04:10.030 --> 04:10.530
All right.

04:10.960 --> 04:16.500
And it's like we have introduced the composite operators, it's one of the important aspect in JavaScript

04:16.510 --> 04:18.040
and in every programming language.

04:18.790 --> 04:21.250
So you should really understand well how they work.

04:22.290 --> 04:28.080
You will see many interesting examples and where things using comparison operators, because we're going

04:28.080 --> 04:31.450
to talk about and discuss what type coercion is in JavaScript.

04:32.130 --> 04:33.120
So let's go ahead.
