In previous video, we have talked about arithmetical operators.
Now it's time to consider a different type of operators, which are a comparison.
So what are prison operators and what they are used for?
Component operators are used in logical statements to determine equality or difference between variables
or values, so they are used to test for true or false, which are boolean values.
As you remember in JavaScript, you will meet very frequently these situations where you have to either
make decisions or choose something, compare values to each other and so on.
For that, you should really understand how comparison operators actually work.
All right, let's create variables.
Verbal and B and I sign both of them five.
As you remember from previous videos, equals sign is used to assign the values to variables, it doesn't
mean equality, it just assigns the value.
So it's called as assignment operator.
In order to compare the equality of those variables, we can use double equals operator, which compares
the values, but it doesn't compare the type of the values.
So I will show you now what exactly means I'm going to work in cons..
For now, you can test your anything you want.
That's why I've told you that Consultive is grateful for JavaScript developers, so.
Right.
A double equals to be.
It's obviously true because the values are the same.
Now let's change the type of one of the values and write it as a string.
It's also true because, as we said, this type of comparison operator doesn't compare the types of
the values and it also cause the types what I mean, in type corrosion, I will show you it's a bit
later.
So using double equals operator seems maybe nice, but it's not actually safe because it may cause unexpected
bugs and errors.
Therefore, we need something else like strict mold and it's triple equals, which compares not only
values but also the types.
Let's prove this right.
A triple equals to be.
You see that it's false because types of the values are different, the data type of variable A is no
and B is a string.
So I recommend you to use a equals comparison operator in practice because it's safer than double equals.
All right.
Let's go ahead and talk about other comparison operators.
Double equals and triple equals.
Operators have opposite ones, not equals and strict not equals, which are written with exclamation
marks.
And they work in the exact same way as the previous ones, but they give us opposite values.
So when A double equals B was true, then A not equals to B is false because it's opposite.
So remember, when double equals gives us for example.
True, they're not equals, gives us false and vice versa.
The same is happening with equals and strict not equals if we write a.
Strict not equals to be.
Then we will get through.
All right, you can find all of these operators, Operator Precedent's table, they have same this number
10.
You can find also other component operators, such as less than less than or equal, greater than and
greater than or equal, although the operators act as simply as you know it from your math class.
They have higher precedence number and it's 11.
As for assignment operator, which is an equal sign, it has the lower precedence number that the comparison
operators and it's three.
All right.
And it's like we have introduced the composite operators, it's one of the important aspect in JavaScript
and in every programming language.
So you should really understand well how they work.
You will see many interesting examples and where things using comparison operators, because we're going
to talk about and discuss what type coercion is in JavaScript.
So let's go ahead.