Operators are used to perform different types of operation on data (variable data or data itself).
JavaScript provide different types of JavaScript operators and they are as follows.

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. String Operators
  5. Logical Operators
  6. Bitwise Operators
  7. Ternary Operators
  8. Type Operators

Arithmetic Operators

To perform mathematical operation on numbers or variable holding numbers.

+Addition (Add two or more values)
Subtraction (Subtract two or more values)
*Multiplication (Multiply two or more values)
/Division (Divides a value with another value)
%Remainder (Returns a remainder after division)
**Exponentiation (Raise First number power of second number )
++Increment (Increase value by 1)
– –Decrement (Decrease value by 1)

Example

<script>
let num1 = 60;
let num2 = 40;
//Addition 
let result = num1 + num2;
document.write(result);

//Subtraction 
result = num1 - num2;
document.write(result);

//Multiplication 
result = num1 * num2;
document.write(result);

//Division
result = num1 / num2;
document.write(result);

//Remainder
result = num1 % num2;
document.write(result);

//Exponentiation 
result = num1 ** num2;
document.write(result);

//Increment 
result = num1++;
document.write(result);

//Decrement 
result = num2--;
document.write(result);
</script>

Assignment Operators

= (equals to) is assignment operator and assigns value to a variable.

<script>
let num1 = 60;
let num2 = 40;

num1 = 30;
</script>

num1 is a variable and value 60 is assigned using = (assignment) operator, similarly num2 is assigned with value 40.

String Operators

Concatenation operator or + symbol – It appends or adds a new string after another string.

<script>
let str1 = "Hello ";
let str2 = "World";
let r = str1 +  str2;
</script>

Comparison Operators

Compare values or types (sometime both) and return true or false.

Operator Use
==equals to
===both value and type are equal
!=not equal
!==both value and type are not equal
>greater than
<less than
>=greater than or equals to
<=less than or equals to
?ternary operator

Example

Operatorslet a = 5, b = 20;Returns
==a == bfalse
===a === btrue
!=a != btrue
!==a !== btrue
>a > bfalse
<a < btrue
>=a >= bfalse
<=a <= btrue

Logical Operators

OperatorsUse
&&logical AND
||logical OR
!logical NOT

Example

Operatorslet a = 20, b = 50, c =30;Returns
&&(a ==b && a > c)false
||(a !=b || a > c)true
!!(a)true

Ternary Operator

It is also a conditional operator with variable on left side and conditions on right side.

Syntax

variable_name = (condition) ? value1:value2 

Example

<script>
let number = 20;
let result = (number % 2) ? "odd number":"even number";
</script>

Bitwise Operators

OperatorsName
&AND
|OR
~NOT
^XOR
<<left shift
>>right shift
>>>unsigned right shift

Type Operators

OperatorDescription
typeofReturns variable type
instanceofReturns true, if object is type of class or returns false if not object is of type class.