<script>
var x = 4 + 4;
</script>
The value of the x variable here would be 8.
We have already used an operator in the previous exercise. When you assigned the variable, you made use of the assignment operator ‘=’.
Arithmetic operators
There are many different operators available to us. The arithmetic-based operators are as follows:
- + Addition. Adds numbers together.
- - Subtraction. Subtracts numbers from one another.
- Multiplication. Multiplies numbers together.
- / Division. Divides numbers from each other.
- % Modulus. Returns the remainder left after a division. For example, 10% 3 would be 1 because 3 * 3 gets you to 9, leaving the remainder 1 to get to 10.
- ++ Increment. This will add 1 to your number.
- – Decrement. This will subtract 1 from your number.
We can combine any number of these together to form an output, like so: