How many types of operator in JS also explain the example?

0 votes
Ravi Vishwakarma asked 10 days ago in Web Application by Ravi Vishwakarma

How many types of operator in JS also explain with example  

1 Answer

1 votes
Ethan Karla answered 9 days ago by Ethan Karla
JavaScript operator are symbol that are used to perform operation on operant. There are following type pf operator.
1. Assignment operator
2. Arithmetic operator
3. Increment and decrement operator
4. Relational operator
5. Logical operator
6. Bitwise operator
7. Special Operator
Assignment Operator
 The following operators are known as JavaScript assignment operators. Denote by the equal symbol (=) in js.
var name = ”MindStick”;
Arithmetic Operator
 Arithmetic operators are used to perform arithmetic operations on the operands. The following operators are known as JavaScript arithmetic operators (+, -, *, /) .
var a=45;
var b=21;
var res=a+b;
console.log('45+21 = '+res);
console.log('45-21 = '+res);
console.log('45*21 = '+res);
console.log('45/21 = '+res);
Increment and decrement operator
 This is used to increment value by one or decrement value by one.
var a=45;
var b=21;
console.log('a++ = '+a);
console.log('--a = '+a);
Relational Operator
 The JavaScript comparison operator compares the two operands. the relational operator are (==, ===, !=, <=, >=, <, >). 
Operator Description Example 
var a=40;
var b=50;
var res= a==b;
  console.log('a==b '+res)
var res= a===b;
  console.log('a==b '+res)
var res= a!=b;
  console.log('a==b '+res)
var res= a>b;
  console.log('a==b '+res)
var res= a<b;
  console.log('a==b '+res)
var res= a<=b;
  console.log('a==b '+res)

Logical Operator

    this is used to compare the more than one comparison. logical operators are (&&, ||, ! ).

var a=40;
var b=50;
var res= a==b && a>b ;
  console.log('a==b '+res)
var res= a===b || a<b;
  console.log('a==b '+res)
var res= a!=b && a<=b;
  console.log('a==b '+res)

Bitwise Operator
 The bitwise operators perform bitwise operations on operands. The bitwise operators are (&, |, ^, ~, <<,>>,>>> ).
var a=40;
var b=50;
var res= a&b ;
  console.log('a==b '+res)
var res= a|b;
  console.log('a==b '+res)
var res= a<<2;
  console.log('a==b '+res)

Special Operator

(?:)                     Conditional Operator returns value based on the condition. It is like if-else.
,                          Comma Operator allows multiple expressions to be evaluated as single statement.
delete               Delete Operator deletes a property from the object.
in                        In Operator checks if object has the given property
instanceof       checks if the object is an instance of given type
new                  creates an instance (object)
typeof              checks the type of object.
void                   it discards the expression's return value.
yield                  checks what is returned in a generator by the generator's iterator.
var a=40;
var b=50;
var res= a<b ? 'A is less than b':'a is grater than b' ;