Oprator in JavaScript
- Operators
- JavaScript language supports following type of operators.
-
Arithmetic Operators.
-
Comparision Operators.
-
LogicalĀ Operators.
- Assignment Operators.
Arithmetic Operators
Assume variable A holds 10 and variable B holds 20 then
Operator |
Description |
Example |
+ |
Adds two operands |
A + B will give 30 |
- |
Subtracts second operand from the first |
A - B will give -10 |
* |
Multiply both operands |
A * B will give 200 |
/ |
Divide numerator by denumerator |
B / A will give 2 |
% |
Modulus Operator and remainder of after an integer division |
B % A will give 0 |
++ |
Increment operator, increases integer value by one |
A++ will give 11 |
-- |
Decrement operator, decreases integer value by one |
A-- will give 9 |
Comparison Operators
Given that x=5, the table below explains the comparison operators:
Operator |
Description |
Comparing |
Returns |
== |
Is Equal to |
x==8 |
false |
x==5 |
true |
||
=== |
Is Exactly equal to (value and type) |
x==="5" |
false |
x===5 |
true |
||
!= |
Is Not Equal |
x!=8 |
true |
!== |
Is Not Equal (neither value nor type) |
x!=="5" |
true |
x!==5 |
false |
||
> |
Is Greater than |
x>8 |
flase |
< |
Is Less than |
x<8 |
true |
>= |
Is Greater than or Equal to |
x>=8 |
false |
<= |
Is Less than or Equal to |
x<=8 |
true |