# ES6 | Operators

• Last Updated : 31 Oct, 2019

An expression is a special kind of statement that evaluates to a value. Every expression consists of

• Operands: Represents the data.
• Operator: which performs certain operations on operands.

Consider the following expression – 2 / 3, in the expression, 2 and 3 are operands and the symbol /is the operator.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

JavaScript supports the following types of operators:

• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Type Operators
• Miscellaneous Operators

Arithmetic Operators: As we know these are the basic mathematical operators available in JavaScript ES6.

OperatorFunction
Subtraction(-)Returns the difference of the values.
Multiplication(*)Returns the product of the values.
Division(/)Performs division and returns the quotient.
Modulus(%)Performs division and returns the remainder.
Increment(++)Increases the value of the variable by one.
Decrement(- -)Decreases the value of the variable by one.

Example:

 ``

Output:

```Sum : 13
Difference : 8
Product : 26.25
Quotient : 4.2
Remainder : 0.5
Value of num1 after pre-increment : 11.5
Value of num1 after post-increment : 11.5
Value of num2 after pre-decrement : 1.5
Value of num2 after post-decrement : 1.5
```

Relational Operators: An operator that compares two values. Relational operators are sometimes called comparison operators.

OperatorFunction
>Returns true if the left operand is greater than right else, false.
<Returns true if the left operand is lesser than right else, false.
>=Returns true if the left operand is greater than or equal to right else, false.
<=Returns true if the left operand is lesser than or equal to right else, false.
==Returns true if both the operands are same else, false./td>
==Returns true if both the operands are the same else, false.
!=Returns true if both the operands are not same else, false.

Example:

 ``

Output:

```11>12 : false
11=11 : true
12<=12 : true
11==11 : true
11!=11 : false
```

Logical Operators: Logical operators are used to combine two or more relational statements.

OperatorFunction
And(&&)Return true if all the relational statements combined with && are true, else false.
Or(||)Return true if at least one of the relational statements combined with || is true, else false.<
!Returns the inverse of the relational statement’s result.

Example:

 `             `

Output:

```13>12 && 12>11 && 9==9 : true
11>12 && 12>11 && 9==9 : false
11>12 || 12>11 || 9==9 : true
11>12 && (12>11 || 9==9) : false
```

Bitwise Operators: A bitwise operator is an operator used to perform bitwise operations on bit patterns or binary numerals that involve the manipulation of individual bits.

OperatorFunction
Bitwise AND(&)Compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 0, the corresponding result bit is set to 0, else 1.
Bitwise OR(|)Compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1, else 0.
Bitwise XOR(^)Inverts the bits of its corresponding operand
Left shift(<<)Will shift the ‘n’ number of bits to the left side, and n bits with the value 0 will be filled on the right side. Example: x=2, t=4, x<<t, for easy evaluation it performs .
Right shift(>>)Will shift the ‘n’ number of bits to the right side, and ‘n’ bits with the value 0 will be filled on the left side. Example: x=2, t=4, x>>t, for easy evaluation it performs .
Zero-fill right shiftShifts a in binary representation b (< 32) bits to the right, discarding bits shifted off, and shifting in zeroes from the left

Example:

 ``

Output:

```2&3 : 2
2|3 : 3
2^3 : 1
~4 : -5
2<>3 : 0
```

Assignment Operators: An assignment operator is the operator used to assign a new value to the variable, property, event or indexer element.

OperatorFunction
Simple Assignment(=)Assigns the value of the right operand to left operand.
Add and Assignment(+=)It adds the right operand to the left operand and assigns the result to the left operand.
Subtract and Assignment(-=)It subtracts the right operand from the left operand and assigns the result to the left operand.
Multiply and Assignment(*=)It multiplies the right operand with the left operand and assigns the result to the left operand.
Divide and Assignment(/=)It divides the left operand with the right operand and assigns the result to the left operand.

Example:

 ``

Output:

```a = b : 10
a += b : 20
a -= b : 10
a *= b : 100
a /= b : 10
```

Type Operators: It is a unary operator. This operator returns the data type of the operand.
Syntax:

`typeof(operand)`

Example:

 ``

Output:

```a is number
b is string
c is : boolean
d is : function
```

Miscellaneous Operators:These are the operators that, does different operators when used at different types of occasions.

OperatorFunction
Negation operator (-)Changes the sign of a value.
Concatenation operator (+)+, when applied to strings it appends them.
Conditional Operator (?)It can use as a ternary operator.

Example:

 ``

Output:

```a+b : GeeksforGeeks=>A Computer science portal.
2>3 :No, It is not.
d = -d : -9
```

My Personal Notes arrow_drop_up