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 : / /
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x