|6||%||Modulus used to find remainder|
|7||++||Increment operation used to increase number by 1|
|8||--||Decrement operation used to decrease number by 1|
Let's discuss each operator and see their examples.
1. Addition operator
Addition operator is used to add two operands. To add operands use
+ symbol in between them. for example
10 + 15 or we can add variable
var a = 5,b = 1, c; c = a + b;.
Concatenating String using + operator
The same operation sign
+ is used to concatenate strings, means attaching two strings side by side. For example
var greeting = "Hello," + " World!" output is Hello, World! .
Adding Strings and numbers
var a = 5 + '5' is a valid expression and gives a string result.
2 + '2' = "22",
2 + 2 + '2' = "42",
2 + 2 + '2' + 1 = "421" and so on.
2. Subtraction operator
The subtraction operator is used to subtract two numbers. For example
20 - 5 also variables can be used
var a = 5,b = 1, c; c = a - b; .
Subtracting numerical string
Unlike addition operator which add and concatenate both, subtraction operator always subtract.
3. Multiplication operator
* multiply operands.
4. Exponential operator
5. Division operator
/ is used to divide two operands.
6. Modulus operator
% is used to find the remainder two operands.
7. Increment operator
++ is used to increase a number by 1.
Increment operator can be used in two ways :
- pre-increment : When Increment operator is used before the operand. Example -
- post-increment : When Increment operator is used after the operand. Example -
Difference in pre-increment and post-increment : Both increase operand by 1 but pre-increment increase value before assigning value to the operand but post-increment increase value after assigning value to number. For example
var a = 10; console.log(a++); // output 10 not 11 and
var a = 10; console.log(a++); // output 11 .
8. Decrement operator
-- is used to decrease a number by 1.
Decrement operator can be used in two ways :
- pre-decrement : When decrement operator is used before the operand. Example -
- post-decrement : When decrement operator is used after the operand. Example -
Difference in pre-decrement and post-decrement : Both decrease operand by 1 but pre-decrement decrease value before assigning value to the operand but post-decrement decrease value after assigning value to number. For example
var a = 10; console.log(a--); // output 10 not 9 and
var a = 10; console.log(a--); // output 9 .