With numbers various mathematical operation can be performed, Javascript provides different operators to work with numbers. They are as follows
+ | Addition (Add two or more values) |
– | Subtraction (Subtract two or more values) |
* | Multiplication (Multiply two or more values) |
/ | Division (Divides a value with another value) |
% | Remainder (Returns a remainder after division) |
** | Exponentiation (Raise First number power of second number ) |
++ | Increment (Increase value by 1) |
– – | Decrement (Decrease value by 1) |
Addition
+ (plus) operator performs addition operation and adds two or more numbers or variables. In String + joins or concatenate two or more strings.
<script>
let a = 60;
let b = 40;
let result = a + b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a + b | ||
Operator | + | ||
Value | 60 | 40 | 100 |
Subtraction
– (minus) operator subtract two or more numbers or variables.
<script>
let a = 60;
let b = 40;
let result = a - b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a – b | ||
Operator | – | ||
Value | 60 | 40 | 20 |
Multiplication
* (asterisk) used to multiply two or more numbers.
<script>
let a = 60;
let b = 40;
let result = a * b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a * b | ||
Operator | * | ||
Value | 60 | 40 | 2400 |
Division
/ (Forward slash) used to perform division.
<script>
let a = 60;
let b = 40;
let result = a / b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a / b | ||
Operator | / | ||
Value | 60 | 40 | 1.5 |
Remainder
% (Modulus or Percentage) is used to get remainder after dividing numbers.
<script>
let a = 60;
let b = 40;
let result = a % b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a % b | ||
Operator | % | ||
Value | 60 | 40 | 2400 |
Exponentiation
** (Double Asterisk without space called Exponentiation Operator). Gives Exponent of First number raises the power of second number,
<script>
let a = 60;
let b = 40;
let result = a ** b;
document.write(result);
</script>
Operand | a | b | result |
Expression | result = a ** b | ||
Operator | ** | ||
Value | 60 | 40 | 1.3367494538843734e+71 |
Increment
++ is increment operator, increases value by 1. It can be used as post or pre increment operator.
<script>
let a = 60;
// Post Increment
let result = a++;
document.write(result);
// Pre Increment
result = ++a;
document.write(result);
</script>
Operand | a | result |
Expression | result = a++ | |
Operator | ++ | |
Value | 61 |
Decrement
— is Decrement operator, decreases value by 1. It can be used as post or pre Decrement operator.
<script>
let a = 60;
// Pre Decrement
let result = a--;
document.write(result);
// Pre Decrement
result = --a;
document.write(result);
</script>
Operand | a | result |
Expression | result = a– | |
Operator | – – | |
Value | 59 |