All right, welcome back to Section three, lesson six operators.
So today we're going to talk about how do you do operations in JavaScript?
So operations are basically simple methods for doing mathematical expressions or logical expressions
that can help us determine how something can be true or false or to change some value, mutate some
number or some string into a different value.
So that's called data mutation, where we're going to change the value from one number to another and
we can use some basic mathematical expressions to do that.
So there are many basic JavaScript operators that arithmetic assignment, comparison, logical and type
of and there are others as well.
So we're just going to start with those and look into them.
OK, so those are the ones are going to take a look at it.
So let's jump into examples.
OK, so now we're in our JavaScript and let's just take a basic number, OK?
Let's just take our basic number that we're going to declare and assign of count of zero.
So what can we do with this count?
OK, well, we can reassign it.
We can set it equal to something else.
And let's just go through the standard arithmetic operations so we can do count equals count plus one.
We could also do count equals count minus one.
And so that would be taking zero to one and then taking one back to zero.
We can also do multiplication so we can times that by one we can do a division as well, divide by one
and there are some others as well.
We could do remainder.
This is also called modulo.
So we could do a remainder operation with this.
So this would be if you divide by that number, then it will get you the remainder.
So, you know, one divided by.
To the remainder would still be zero or zero divided by two, the remainder would still be zero.
OK, and then we can do increment.
So if you want to do this, you could just do count plus plus.
And that's going to be the same as count equals count plus one.
You can actually do this.
From the other perspective you could do plus plus count.
There's a minor difference between those two.
So count plus plus is going to add one to it.
But technically this actually inside of a function return.
So this is a very unique case.
This is actually going to return, going to change the count up by one and then it's going to return
the final value in this example.
It actually returns the value and then it adds the one after it returns it.
So you actually don't get the same return value in either case.
OK, but both of these do count plus one.
So they're the same functionally as this one right here.
OK, all right.
And then there are a few others.
So we could do count equals minus count.
So this would be get the negative of that option.
OK.
Oh, I guess corollary to this, you could do count minus, minus or minus minus count.
OK, so that goes that does count minus one in the same exact way as this does count plus one.
OK, you can also do exponents so we can do exponents.
So if we do that does count to the power of.
So we can do count to the power of two.
OK, so these are the arithmetic operations I'm going to call this right here.
Arithmetic
operations, OK, operators.
But there are many more than this, so let's take a look at comparison operators next day.
So there are some comparison operators now with comparison operators, you're going to be doing some
logical comparisons.
You're going to find out whether something is the same as something else.
OK, so this expression is going to resolve as either true or false.
So you can see count equals zero.
Now, this is going to be a check to see whether it is true or false.
OK, and that's called a boolean value.
OK.
It's to find out whether it's a boolean value.
You can do the same thing, but slightly different.
Let's just copy the first part of this.
You can do the same thing, but slightly different and say not equal to zero.
And there's another actually sorry, this is only one exclamation.
So the way that you do not equal to is exclamation equals zero.
OK, and then there's a strict equal also called congruence.
So you do count equals equals equals zero.
So what this will do is it will check to see that their values are the same, not just the same, but
there's also a sameness in the type.
So they're the same data type.
So that means if this was actually the string zero, so this would actually be a string like, you know,
as you would have in a word, it would not actually be true that it would be district equal to zero.
OK, you can do this, not equal, and that is with the exclamation equals.
So in the case where you were to check whether they were the same data type, if they were not the same
data type or the value was different, this would be seen as true.
And then the next one is you're probably more familiar with count greater than zero and count less than
zero.
OK, and then there are a few more of those.
So there's count greater than or equal to zero and there's count less than or equal to zero.
OK, and obviously you can have any expression on the left side of this and any expression on the right
side of this.
OK, so it's a little bit simpler than simply an assignment.
We're not assigning any values here.
We're not mutating or changing any data.
All we're doing is checking to see whether or not something a relationship between these two values
is true or false.
So that's the difference there.
There are a lot of other types of operations we could do.
I'm just going to show you a few others what are called the assignment operators.
So these assignment operators can kind of shortcut some of the other things that we've been looking
at.
So first things, first count equals zero.
That is our regular old assignment operator if we want to do an addition assignment.
So that's combining the addition operator and the assignment operator.
Then we can do count plus equals one or any other number, OK, or any other value.
You could do this with strings and you could use this to concatenate strings together.
So that's addition assignment.
So this is the same as count equals count plus one.
And then you can do a subtraction, you could do count minus equals and do the same thing as count equals
count minus one, as you can see up on line five.
And you can do multiplication assignment so you can count eight times equals.
Let's just do that for differences and then you could do a division assignment.
So you count divided equals
and you can do the remainder assignment.
So same thing right here.
And count equals exponentiation assignment.
So you can do just like that.
So this is the same as count equals count to the power of some other number.
OK.
And there are also a number of others you can look at left shift assignment, bitwise logical assignment
in a number of different things.
So feel free to look at the resources for how you can use some of these other operations.
But these are the ones that you're going to be using most of the time.
There are a few other logical operators that I want to cover real quick.
So these kind of go along with the comparison operators.
You can just one thing you could do is just say our account is greater than zero.
And so these are these are what's called logical operators.
Logical operators count is greater than zero and count is greater than three.
So that means they both have to be true at the same time.
Or we could say less than three.
So both have to be true at the same time for this to be the case.
There's a very similar operation for not and but for so you could say or with the pipe key.
And that is the one that's just to the left of the enter key, just above the right shift on the keyboard.
And you have to you have to make sure you do you have to do a shift on that.
OK, and this means or so you're saying, this one or the other one.
OK, so either of these can be true and then this would result as true.
OK, so those are the basic operators.
There are a few others that you could learn.
String operation is just you know, you can concatenate using the plus which is the addition operator
and there are a few others as well, but that is it for the basics of JavaScript operators.
And we'll see you in the next lesson.