It's time to talk about the next important concept in JavaScript, which is called operators, so what
is an operator?
Operators of special functions that take two parameters and return results.
You may already know some of them, especially from your math class.
What do we see?
For example, five plus five.
We all know that we have to add those numbers because plus generally means additions and therefore the
result is 10.
Now, let's see what happens in JavaScript creates variable A.
And assigned to it five plus five.
And then run it in Castle.
You see, we have.
So how does JavaScript and you know that it has to add these numbers?
The reason is that it's already built there the right function, which is automatically called one JavaScript
engine system, plus as the numbers and gives us the results.
In the same way, works subtraction.
Multiplication.
And division.
All right, sometimes we are using multiple operations in one statement, like five plus five and multiplied
to five.
So what do you expect to get here because of that JavaScript and generates the code from left to right?
You may think that first it would add five to five and then multiply it to another five, which then
will output 50.
Let's see what happens.
You said that we got 30 because it follows the exact same rules.
As we know from math at first, JavaScript engine multiplies and then performs additions.
In JavaScript, it's called Operator Precedent's, you can look into the table where Operator Precedent's
is represented.
Let's search it in Google, right.
Operator Precedent's table.
You can visit this website developer, Dot Mozilla dot org, which actually is very useful guide for
JavaScript, and you can find almost everything regarding JavaScript on that site.
All right.
So here we have operator precedence.
Table first column represents precedence number, which defines the sequence of the operations.
As you remember from the previous example, JavaScript engine has performed at first multiplication
and then addition.
And if you look at the table, you will see that multiplication has precedence of 14, which is higher
than the precedence of addition, which is 13.
You also see that addition and subtraction have the same number of precedence.
It means that JavaScript engine will perform operation from left to right, and it's called associativity.
Some of the operators have associativity from left to right and some of them have right to left.
It also depends on type of operator.
The highest number of precedence has grouping operator, which is parentheses.
So if we pass the addition with embraces, the result will be different and will get 50.
All right, operator Preston's table is a very useful source, you can find their operator we are interested
in.
I recommend to review this table and introduce to other operators and figure out how they work.
All right, so we have talked about arithmetical operators and also discussed what operator precedence
and Associativity are.
See you in the next lecture.