It's also worth pointing out, and I mentioned this before,
but I want to emphasize it again.
That of course you are not limited to two numbers only
when you perform a certain operation.
It is perfectly fine to have
an operation like this, for example.
You can use as many values as you want in such operation.
You can, of course also use floating point numbers.
So decimal numbers here as well, by using a dot
as a separator between the decimal place
and the number in front of the decimal place,
that's all possible.
If you do use multiple values in your calculation though,
as we do it here, and this is the result,
then it is important to keep in mind
that regular mathematical rules apply,
which means that multiplication and division
have a higher priority than using plus or minus.
And then for here,
this would be the first part that's evaluated.
So we get 50 as a result,
and then 50 would be deducted from ten plus three
which is why we get -37 as a result.
This might or might not be obvious, now it hopefully is.
If you ever want to change these rules,
you can do it just like you do it in regular math as well.
You can add brackets, parentheses around the operation
that should be evaluated first,
because that now in turn has a higher priority
then the regular priority.
So now this term would be evaluated first
and then the result of this term
would be multiplied with ten.
And that's why we now get a totally different result here.
So that's what you should keep in mind
about mathematical operations in your JavaScript code.
Now, as I mentioned before,
you can also store results of operations in variables.
And I briefly want to come back to that.
We can add a result variable,
and we could store the result of this calculation
in this variable.
Or of any other calculation.
Of course you can then also reassign the value.
You can now store a new value in that variable,
and that can be any kind of value.
For example, I could then store ten times four in result.
Now I'm emphasizing this
because there is one way of changing a variable
that stores a value that can be shortened a little bit.
And for that, let's say that for result,
which has 40 after this line here,
or which holds a value of 40 after this line.
We now want to add one to result.
Now we can write it like this.
This is perfectly fine JavaScript code.
You can use a variable on the right side
of such a variable assignment,
even if you're assigning the result here,
to the existing variable.
Even if the variable you're assigning
to is being used on the right side as well.
This works because JavaScript will always evaluate
and execute the right side of the equal sign first
with the old value of result.
So the value that is locked in, in line 13 so to say.
And only once this calculation has been performed,
the result of that calculation will be stored
in that variable.
So only then the variable value will change.
That's why we can use a variable
on the right side of the equal sign.
Even if we're assigning to the very same variable.
Now there are a couple of operations which are very common
and therefore can be shortened, though.
For example, if you add one to an existing variable.
Then you can write it like this,
or you can write it like this.
This might look strange,
but that is the same as saying
result equals result plus one, it's just a shorter form.
We've got something similar for subtracting one.
Here we have result minus minus.
Now sometimes of course,
you don't just want to add or subtract one.
Sometimes you maybe want to add five, let's say.
In that case, you can't use the plus plus notation,
but we still got a shorter version of writing this.
You can write plus equals five,
and this is equal to writing it like this.
So whenever you use a variable
on the right side of an equal sign
and you then store the result in the very same variable,
you can use shortcuts like this
for simple mathematical operations.
That also exists for minus, if you want to subtract
and also for division and multiplication.
So we can also shorten these statements here, if we want to.
This all works.
If I now console lock the result here at the bottom
after changing it a couple of times,
you will see that in that developer tools console,
you've got a bunch of valid results
from these lines of code that we added here.
And these are just some shortcuts which can be useful
if you're doing some mathematical operations
and you are changing an existing variable
based on its previous value.
Now I will delete all of that for the moment,
but these are a couple of shorthand notations
that are worth keeping in mind.
You will also encounter them again later in the course.