Javascript support different types of operators. They are:
- Arithmetic Operators
- Comparision Operators
- Logical (or Relational) Operators
- Assignment Operators
- Conditional (or ternary) Operators
—–>Arithmetic Operators
JavaScript supports arithmetic operators . A typical arithmetic operation operates on two numbers.
eg:
var x=100=50;
or
var x= a+b;(using variables)
Operator | Description |
---|---|
(+) Addition | Add two operands eg:A+B(A=10;B=30 will give 40) |
(-)Subtraction | Subtracts the second operand from the first eg: A-B(A=10;B=30 will give -20) |
(*) Multiplication | Multiply both operand eg:A*B(A=2;B=4 will give 8) |
(/)Division | Divide the numerator by the denominator eg:A / B (A=20;B=10 will give 2) |
( % )Modulus | Outputs the remainder of an integer division eg: B % A (A=10;B=20 will give 0) |
(++) Increment | Increases an integer value by one eg: A++ (A=10 will give 11) |
(–) Decrement | Decreases an integer value by one eg: A– (A=10; will give 9) |
—->Comparision Operators
Javascript support comparison operator
Operator | Description |
---|---|
( = = )Equal | Checks if the value of two operands are equal or not. eg: A == B (A=10;B=20; is not true). |
( != ) Not Equal | Checks if the value of two operands are equal or not, if the values are not equal, then the condition becomes true. eg: A != B (A=10;B=20 is true.) |
( > ) Greater than | Checks if the value of the left operand is greater than the value of the right operand, if yes, then the condition becomes true. eg: A > B (A=10; B=20 is not true.) |
( < ) Less than | Checks if the value of the left operand is less than the value of the right operand, if yes, then the condition becomes true. eg:A < B(A=10;B=20; is true) |
( >= ) Greater than or Equal to | Checks if the value of the left operand is greater than or equal to the value of the right operand, if yes, then the condition becomes true. eg:A >= B (A=10;B=20 is not true) |
( <= ) Less than or Equal to | Checks if the value of the left operand is less than or equal to the value of the right operand, if yes, then the condition becomes true. eg: A <= B (A=10; B=20 is true) |
Logical (or Relational) Operators
Javascript also support different types of logical oprator.
Operator | Description |
---|---|
( && ) Logical AND | If both the operands are non-zero, then the condition becomes true. eg: A && B. |
(||) Logical OR | If any of the two operands are non-zero, then the condition becomes true. eg: A || B. |
( ! ) Logical NOT | Reverses the logical state of its operand. If a condition is true, then the Logical NOT operator will make it false. eg: ! (A && B). |