JavaScript Operators

  • Arithmetic Operators
  • Comparison (Relational) Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators

Arithmetic Operators

Arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.

OperatorsMeaningExampleResult
+Addition4+26
Subtraction4-22
*Multiplication4*28
/Division4/22
%Modulus operator to get
the remainder in integer division
5%21
++IncrementA = 10;
A+ +
11
DecrementA = 10;
A− −
9

Relational Operators

OperatorsMeaningExampleResult
<Less than5<2False
>Greater than5>2True
<=Less than or equal to5<=2False
>=Greater than or equal to5>=2True
=Equal to5==2False
!=Not equal to5! =2True
===Equal value and same type5 === 5
5 === “5”
True
False
!==Not Equal Value or Not
same type
5 ! == 5
5 ! == “5”
False
True

Logical Operators

OperatorsMeaningExampleResult
&&Logical and(5<2)&&(5>3)False
||Logical or(5<2)||(5>3)True
!Logical not!(5<2)True

&&

Operand 1 Operand 2Result
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

||

Operand 1 Operand 2Result
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

!

OperandResult
FalseTrue
TrueFalse

Bitwise Operators

OperatorMeaning
<<Shifts the bits to left
>>Shifts the bits to the right
~Bitwise inversion (one‟s complement)
&Bitwise logical AND
|Bitwise logical OR
^Bitwise exclusive or

Bitwise logical AND &

Operand 1Operand 2Result (operand1&operand2)
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse
Operand 1Operand 2Result (operand1&operand2)
111
100
010
000

Bitwise logical OR |

Operand 1Operand 2Result (operand1|operand2)
True 1True 1True 1
True 1False 0True 1
False 0True 1True 1
False 0False 0False 0

Bitwise XOR ^

Operand 1Operand 2Result (operand1^operand2)
True 1True 1False 0
True 1False 0True 1
False 0True 1True 1
False 0False 0False 0

Bitwise NOT ~

OperandResult
True 1False 0
False 0True 1

Assignment Operators

OperatorExampleEquivalent Expression
=𝑚 = 10𝑚 = 10
+=𝑚 += 10𝑚 = 𝑚 + 10
−=𝑚 −= 10𝑚 = 𝑚 − 10
∗=𝑚 ∗= 10𝑚 = 𝑚 ∗ 10
/ =𝑚 / =𝑚 = 𝑚/10
% =𝑚 % = 10𝑚 = 𝑚%10
<<=𝑎 <<= 𝑏𝑎 = 𝑎 << 𝑏
>>=𝑎 >>= 𝑏𝑎 = 𝑎 >> 𝑏
>>>=𝑎 >>>= 𝑏𝑎 = 𝑎 >>> 𝑏
& =𝑎 & = 𝑏𝑎 = 𝑎 & 𝑏
^ =𝑎 ^ = 𝑏𝑎 = 𝑎 ^ 𝑏
| =𝑎 | = 𝑏𝑎 = 𝑎 | b
Tagged : / /

Tutorial for Assignment operators

What is Assignment operators?

PHP Assignment operators are used to assign values to variables. The right side value is substituted for the left side value in the operand variable. Operators in this category are in charge of assigning variables. The most frequent assignment operator is =, which assigns the operand’s right side to the left variable.

  • Assignment Same as… Description
  • x = y x = y The left operand gets set to the value of the expression on the right
  • x += y x = x + y Addition
  • x -= y x = x - y Subtraction
  • x *= y x = x * y Multiplication
  • x /= y x = x / y Division
  • x %= y x = x % y Modulus

Example:-

Output:-

Tagged : / / / / / /