Hello and welcome to this video.
In this video.
I'll be introducing you to Javascript operator precedence operator precedence.
Basically describes the order in which operations are performed in an arithmetic expression.
The best way to show you this is by actually illustrating an example.
So I've got my Consul here so I'm going to create a variable and then to create a variable Hord.
J You could call your variable anything.
I'm going to give it a value of 150
plus
and multiply by four.
This is going to be in value for my variable called J.
Lo fi press enter and try call this variable by name.
Is going to give me a value of 430.
Now if you used a calculator you get a different result.
So if you put 150 plus 70 times four on your calculator it will return a value of eight hundred and
eighty.
The reason we get a different value here inside the console is that program in and also in Jaba script
there is a precedence of operators.
So what that basically means is that in terms of the order in which the operations perform multiplication
and division have a higher precedence than addition subtraction.
That is why the multiplication is done first so it will do the 70 times for first before it adds the
150.
So that is known as a precedent.
So the president is out there where there is multiplication and division involved.
It all take higher order than where there is addition subtraction involved so he does the multiplication
first.
Then the addition if there was division it would do that first and then the multiplication.
There is a precedence in the operator action.
However you can use parentheses to change that order.
If you wanted the additions to be done first or you need to commit to a variable jihae and Winters said
that two equates to a parent this is typee a 150
plus 70
and I will close in parenthesis.
So what that does it will do the addition.
First because I have wrapped it around the parent forces which gives it a higher order.
Then I can now do the motts application.
So if I do this return this variable it will now give me a value of eight hundred and eighty because
I have forced the addition to compute that operation first before the multiplication is done.
So I press enter.
If I call the variable Jane now I should get eight.
Which is me.
Figure you will get.
If you had used a standard calculator program in Javascript there is a precedence in the way the operator
actions are performed.
So if you want a particular operator to compute its value first you need to wrap it round parentheses
and that would give it a higher order in the operator precedence.
So that's basically how operate precedent works.
Thank you for watching.
Bye for now.