operator to operate on one or more variables or values (operands) and return a new value
Depending on the operation performed, the operators can be divided into the following categories:
(1) Arithmetic operators
(2) Comparison operators
Operator |
Speak clearly |
Show Example |
== |
Equals. Returns true if the two operands are equal. |
A = = B |
!= |
Not equal to. Returns true if the two operands are not equal. |
Var2! = 5 |
> |
Greater than. Returns true if the left operand is greater than the right operand. |
Var1 > Var2 |
< |
Less than. Returns true if the left operand is less than the right operand. |
Var2 < var1 |
<= |
is less than or equal to. Returns true if the left operand is less than or equal to the operand to the right. |
VAR2 <= 4 Var2 <= var1 |
>= |
Greater than or equal. Returns true if the left operand is greater than or equal to the right operand. |
VAR1 >= 5 Var1 >= var2 |
(3) Logical operators
Operator |
Value |
Speak clearly |
and (&&) |
Expr1 && EXPR2 |
It is only when expr1 and expr2 are true that they return true. Otherwise, returns false. |
or (| |) |
Expr1 | | Expr2 |
Returns true if one of the expressions is true, or two expressions are true. Otherwise, returns false. |
Non - (!) |
!expr |
If the expression is true, False is returned. If False, returns TRUE. |
Operators in JavaScript