JavaScript Operators

JavaScript supports the following types of operators:

  1. Arithmetic
  2. Assignment
  3. Comparison
  4. Logical
  5. Bitwise
  6. Ternary
  7. typeof, instanceof

Arithmetic operator list:

OperatorTypeDescription
+ArithmeticAddition
ArithmeticSubtraction
*ArithmeticMultiplication
/ArithmeticDivision
%ArithmeticModulus
++ArithmeticIncrement
ArithmeticDecrement

below is the sample code:

Output:

Assignment operator List:

OperatorTypeDescription
=AssignmentAssignment
+=AssignmentAddition Assignment
-=AssignmentSubtraction Assignment
*=AssignmentMultiplication Assignment
/=AssignmentDivision Assignment
%=AssignmentModulus Assignment

example code:

Console Output:

Comparison operator List:

OperatorTypeDescription
==ComparisonEqual to
===ComparisonStrict Equal to
!=ComparisonNot Equal to
!==ComparisonStrict Not Equal to
>ComparisonGreater Than
<ComparisonLess Than
>=ComparisonGreater Than or Equal to
<=ComparisonLess Than or Equal to

example code:

output would be as mentioned in code comments.

Note: check console log for output

Logical operator List

OperatorTypeDescription
&&LogicalLogical And
 
!LogicalLogical Not

example code:

Output: In the above code, the && operator returns true if both operands are true, otherwise it returns false. The || operator returns true if either operand is true, otherwise it returns false. The ! operator returns true if the operand is false, and false if the operand is true.

Note: check console log for output

Bitwise operator List

OperatorTypeDescription
&BitwiseBitwise And
Bitwise
^BitwiseBitwise Xor
~BitwiseBitwise Not

Example Code:

In the above code:

  • The & operator performs a bitwise AND operation.
  • The | operator performs a bitwise OR operation.
  • The ^ operator performs a bitwise XOR operation.
  • The ~ operator performs a bitwise NOT operation.

Note: check console log for output

Ternary operator list

OperatorTypeDescription
?TernaryTernary operator
:TernaryTernary operator

Example Code:

In the above code, the Ternary operator ? : is used to assign a value to result based on the comparison between x and y. If x > y is true, result is assigned the value of “x is greater”.

If x > y is false, result is assigned the value of “y is greater”.

Note: check console log for output

typeof, instanceof operator List

OperatorTypeDescription
typeofUnaryType of operator
instanceofRelationalInstanceof operator

In the above code, the typeof operator returns a string indicating the type of the operand.

The instanceof operator returns true if the object on the left is an instance of the type specified on the right.

 In the code above, z is an instance of the Array type, so z instanceof Array returns true. On the other han

Note: check console log for output

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top