If you like math this is the lesson for you as we're going to be looking at javascript operators and
we have seen a little bit of these in the earlier lesson.
So we're going to be focusing on how to use operators what are available or what operators are available
and the order of arithmetic operators in javascript.
So if you remember from high school or public school that there is an order when you are adding subtracting
multiplying or division.
So there is a standard order of operations.
So we do adding subtracting multiplication and division.
And if we want to change around that order then we need to wrap it with brackets and there's more information
available about arithmetic operators at the mud solar developer network.
So they've got a great example here of two plus three minus one.
Quick what's the answer.
It's four.
This one gets a little bit more complicated.
So we have four times three divided by two.
So the answer here is that we're doing multiplication and then division.
So that's the order of operation.
So four times three is twelve divided by two is outputting six.
This one is also a little bit more complicated and we're doing a modulus and then we're also multiplying
by the exponential.
So we are not going to be exploring that in the upcoming lesson but you're welcome to try that out in
your console and play around with it.
And although we are looking at modulus and we explain that more detail as we go through the lesson also
there is addition.
So of course Ed. Just adding it together.
And then there was some of the additions with strings that we saw which is also known as concatenation
where we do a five plus foo ends up as a string value.
So javascript again is trying to convert these as best as possible to either numbers or strings and
adding them together so if we have a boolean value plus a number we end up with addition to boolean
we end up with additions and so on.
There's also subtraction.
So when we're subtracting a number and if we're doing a string minus three then we're being returned
back not a number.
And as we saw in the last lesson that tries to convert the string to a number.
So that's where we get non reviewing return back.
We also have a division.
So we've got division by all the different values and then the values that are being returned multiplication
of course.
So we have two times two is four negative two times two is negative four.
And then if we multiply a value and we get not a number but if we multiply infinity so remember ANYTHING
BY A zero is going to be returned back as a zero.
But we're getting infinities so it's not a number.
So this is one of the things to keep in mind.
But very rarely are you ever going to be working with infinity.
So don't have to usually worry about that.
And of course we can't multiply a string by two.
Doesn't make sense.
The one that we did want to look at and that might be something that might you might be not be familiar
with is the modular operator and what this is.
This is the remainder essentially.
So we get the value and if we do 12 modulus five we end up with two so two is the remainder that's remaining
there after we divide twelve by five.
So we get it goes in twice but we get a remainder of two so 10 divided by five is the two sets we're
getting the remainder.
So that one is a little bit confusing because it is the remember remainder.
And then there's some other operators that we're not going to be exploring within the lesson.
So there's a lot of great information on again module the developer network.
So we do need to look at order and that was something that we saw that we've got multiplication division
addition subtraction.
So that's the order of precedence of operator precedents.
And again referring to the module of the Developer Network.
So we get three plus four times five.
Quick.
What's the answer.
Okay three plus four is seven times five would be thirty five but we forgot the order of precedence
the operator precedents.
So we're doing multiplication first.
So four times five is 20 and then plus three.
And that's why our answer is twenty three.
So it does take some getting used to unless you're familiar with it from a high school or public school
the order is still the same thing.
And if we did want to do three plus four multiplied by five that means that we would have to wrap it
in brackets and I'll show you quickly how that works in the console.
So if we take a value and if we take the three rapid in brackets and then we multiply it by five we're
gonna get thirty five where as if we have three plus four times five we're going end up with twenty
three and you get the picture.
So wrapping that in brackets just like you do with regular math outside of coding it's gonna work the
same way.
So keep in mind that there is an order.
And if you are doing some math and if you're not getting the value that you're expecting take a look
at the ordered that it's being presented in.
There's the modulus.
So we did look at this and I know 12 modulus five returning of two is a little bit confusing because
it also means that five goes into twelve twice.
So there we.
That number is a little bit confusing but if we do 13 modulus five you're going to see that we're returning
back a value of three and a little bit with it.
So we've got 13 modules five.
You see that the return is 3.
So 14 modules 5 what's the answer.
Quick four and five modulus 5.
And what's the answer going to be this is maybe a little bit of a trick question but that's 0.
So try out some of the formulas try at some of the math operators.
Remember the order of precedents.
Challenge yourself.
Have some fun with it.
We're gonna jump in the next lesson going into more detail a.
Operators that are available in JavaScript.