Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Arithmetic Operators

One of the most basic operations we can perform with JS is Math operations. Exactly like in Math, in order to perform different operations we use different operators. These are the most commonly used Arithmetic JS operators, that allow us to perform basic math.

 

1)  +   For addition

2)  -   For subtraction

3)  *   Multiplication

4)  /   Division

5)  %   The remainder of the division. This is called as the  modulo operator and has nothing to do with percentage. 

p.s. When your operation is comprised of more than one operations, then the order of precedence is the same as in regular math. Multiplication and division, first addition and subtraction last. You can change the order of execution by grouping operation inside parentheses like in regular math. 

You can take a look at the full JS list operators order of precedence list here.

There are additionally two more operators, the increment and the decrement operator. These are very useful while working with numbers, and we want to update the value of number to what it was until now, plus one. Then we can use the ++ sign in front of the variable. 

For example:

var a = 10;

a++;

console.log(a) // prints 11.

The line a++ is equivalent to a = a + 1, so not only increases the value, but also assigns the value to variable in order to update it. That's why increment and decrement operators are assign type operators and not strictly arithmetic, although they perform an arithmetic operation partially.

The same for the decrement operator (though -- is used instead) to decrease the value by one.

* Perform 3 actions for each operator specifically and print the results to console. Before every new operator, comment out what exactly does the operator that follows. At the end you should have 15 logs to console and 5 comments.