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 lessons.
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's 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 Modula Developer Network.
So they've got a great example here of two plus three minus one.
Quick, what's the answer?
It's for 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 12, 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's additions.
So of course, addition, 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 FU 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 additions to booleans, 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 on 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-moving 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 infinity.
That'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 you 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 12 by five.
So we get it goes in twice, but we get a remainder of two.
So ten 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 Segan 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 precedence and again, referring to the module of the
developer network.
So we get three plus four times five.
Quick, what's the answer?
OK, three plus four, seven times five would be 35, but we forgot the order of precedence, the operator
precedence.
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 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 rapide in brackets and then we multiply it by five,
we're going to get 35.
Whereas if we have three plus four times five, we're going to end up with twenty three and you get
the picture.
So wrapping it in brackets, just like you do with regular math outside of coding, it's going to 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 order 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 12 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 modulus five and you see that the return is three.
So 14 modulus five.
What's the answer?
Quick four and five.
Modulus five.
And what's the answer going to be?
This is maybe a little bit of a trick question, but that's a zero.
So try out some of the formulas, try some of the math operators.
Remember the order of precedence, challenge yourself, have some fun with it.
We're going to jump in the next lesson going into more detail about operators that are available in
JavaScript.