WEBVTT

00:00.840 --> 00:06.960
It's time to talk about the next important concept in JavaScript, which is called operators, so what

00:06.960 --> 00:07.920
is an operator?

00:08.400 --> 00:13.050
Operators of special functions that take two parameters and return results.

00:13.680 --> 00:17.190
You may already know some of them, especially from your math class.

00:17.610 --> 00:18.080
What do we see?

00:18.090 --> 00:20.130
For example, five plus five.

00:21.250 --> 00:27.520
We all know that we have to add those numbers because plus generally means additions and therefore the

00:27.520 --> 00:28.510
result is 10.

00:29.700 --> 00:33.000
Now, let's see what happens in JavaScript creates variable A.

00:34.420 --> 00:36.430
And assigned to it five plus five.

00:39.250 --> 00:40.720
And then run it in Castle.

00:43.100 --> 00:43.970
You see, we have.

00:45.410 --> 00:49.280
So how does JavaScript and you know that it has to add these numbers?

00:49.880 --> 00:55.700
The reason is that it's already built there the right function, which is automatically called one JavaScript

00:55.700 --> 01:00.200
engine system, plus as the numbers and gives us the results.

01:01.400 --> 01:03.680
In the same way, works subtraction.

01:05.930 --> 01:06.860
Multiplication.

01:08.780 --> 01:10.050
And division.

01:12.140 --> 01:21.470
All right, sometimes we are using multiple operations in one statement, like five plus five and multiplied

01:21.470 --> 01:21.990
to five.

01:22.790 --> 01:28.560
So what do you expect to get here because of that JavaScript and generates the code from left to right?

01:29.090 --> 01:35.030
You may think that first it would add five to five and then multiply it to another five, which then

01:35.030 --> 01:36.370
will output 50.

01:37.610 --> 01:38.660
Let's see what happens.

01:39.710 --> 01:44.840
You said that we got 30 because it follows the exact same rules.

01:44.840 --> 01:50.900
As we know from math at first, JavaScript engine multiplies and then performs additions.

01:51.870 --> 01:58.620
In JavaScript, it's called Operator Precedent's, you can look into the table where Operator Precedent's

01:58.620 --> 01:59.520
is represented.

02:00.180 --> 02:03.180
Let's search it in Google, right.

02:03.180 --> 02:05.250
Operator Precedent's table.

02:08.340 --> 02:15.210
You can visit this website developer, Dot Mozilla dot org, which actually is very useful guide for

02:15.210 --> 02:19.890
JavaScript, and you can find almost everything regarding JavaScript on that site.

02:20.580 --> 02:21.060
All right.

02:21.540 --> 02:23.580
So here we have operator precedence.

02:23.580 --> 02:30.060
Table first column represents precedence number, which defines the sequence of the operations.

02:30.690 --> 02:36.360
As you remember from the previous example, JavaScript engine has performed at first multiplication

02:36.360 --> 02:37.400
and then addition.

02:38.040 --> 02:44.850
And if you look at the table, you will see that multiplication has precedence of 14, which is higher

02:44.850 --> 02:47.410
than the precedence of addition, which is 13.

02:48.120 --> 02:52.080
You also see that addition and subtraction have the same number of precedence.

02:52.590 --> 02:59.640
It means that JavaScript engine will perform operation from left to right, and it's called associativity.

03:00.540 --> 03:06.640
Some of the operators have associativity from left to right and some of them have right to left.

03:07.230 --> 03:09.600
It also depends on type of operator.

03:10.980 --> 03:15.350
The highest number of precedence has grouping operator, which is parentheses.

03:16.290 --> 03:23.400
So if we pass the addition with embraces, the result will be different and will get 50.

03:24.560 --> 03:31.160
All right, operator Preston's table is a very useful source, you can find their operator we are interested

03:31.160 --> 03:31.420
in.

03:31.820 --> 03:37.250
I recommend to review this table and introduce to other operators and figure out how they work.

03:38.340 --> 03:45.300
All right, so we have talked about arithmetical operators and also discussed what operator precedence

03:45.300 --> 03:46.880
and Associativity are.

03:47.400 --> 03:48.720
See you in the next lecture.
