List Of JavaScript Operators

JavaScript provides different type of operations same as other programming languages. There are some additional operators which make javascript more suitable for programming.

Javascript supports the following types of operators:

1) Arithmetic Operators

They are used to perform different arithmetic operations between two or more variables.

OperatorDescriptionExample: (here m = 8, n = 2 )
+Additionvar x = m + n   // Ans: 10
Subtractionvar x = m – n // Ans: 6
*Multiplicationvar x = m * n    // Ans: 16
/Divisionvar x = m / n // Ans: 4
%Modulusvar x = m % n    // Ans: 0

2) Logical Operators

They are used to perform logical operations like AND Operation, OR Operation and NOT operations between two or more variables.

OperatorDescriptionExample: (here m = 8, n = 2 )
&&ANDvar x = (m > 0) && (n < 5)    // Ans: true
||ORvar x = (m == 8) || (n < 0)    // Ans: true
!NOTvar x = !(n == m – 6)    // Ans: false

NOTE:

  • AND operation is true if all conditions are true otherwise it is false.
  • OR operation is false if both conditions are false otherwise it is true.
  • NOT operation returns opposite result of a condition.
  • Logical operations are used to get result for given conditions and based on that result further actions are taken.

3) Comparison Operators

They are created to compare two or more variables. They are mostly used with logical operators.

OperatorDescriptionExample: (here m = 8, n = 2 , int)
>greater thanvar x = m > n    // Ans: true
<less thanvar x = m < 5    // Ans: false
>=Greater than Or Equal tovar x = m >= n    // Ans: true
<=less than Or equal tovar x = n <= 2    // Ans: true
==Equal tovar x = (m == n)    // Ans: false
===Equal to with Equal typevar x = (m === 8)    // Ans: true
!=Not Equal tovar x = m != n    // Ans: true
!==Not Equal to with Not Equal typevar x = m !== 5    // Ans: true

4) Increment – Decrement Operator

They are used to increment and decrement the values.

OperatorDescription
++Increment
Decrement

Note: Based on the position they are used, we can divide them into two types.

1) Pre-increment / Post-increment

Example: (m =8 , n = 2)
Pre increment
var x = m++; // Ans: x = 8 , m = 9
Post increment
var x = ++n // Ans: x = 3 , n = 3

2) Pre decrement / Post decrement

Example: (m =8 , n = 2)
Pre decrement
var x = m–; // Ans: x = 8 , m = 7
Post decrement
var x = –n // Ans: x = 1 , n = 1

5) Conditional Operator

They are also called ternary operators. According to the condition, the result value is assigned to a variable.

Syntax:

Variable name = ( condition ) ? val1 : val2

Explanation:

If the condition is true, then val1 is assigned to the variable; otherwise, val2 is assigned to the variable.

Example: (m =8 , n = 2)
var x = (m > 5) ? 7 : 3 // Ans: x = 7
var x = (n == 5) ? 7 : 3 // Ans: x = 3

6) Bitwise Operator

JavaScript supports different bitwise operators. During these operations, data is converted into a 32-bit format, and then operations are performed, again the result is converted back to javascript number.

OperatorDescriptionExampleSame asResultDecimal
&ANDx = 4 & 10100 & 000100000
|ORx = 4 | 10100 | 000101015
~NOTx = ~ 4~0100101111
^XORx = 4 ^ 10100 ^ 000101015
<<Left shiftx = 4 << 10100 << 110008
>>Right shiftx = 4 >> 10100 >> 100102

7) String Operator

They are used to concatenate two or more strings in javascript.

Example 1:

var e1 = “I am”;
var e2 = “ Errorsea”;
var e3 = e1 + e2; // Ans: “I am Errorsea”

Example 2:

var e1 = “I am”;
var e2 = “ Errorsea”;
var e1 += e2; // Ans: “I am Errorsea”

8) The type of Operator

It returns the type of a variable.

Example:

type of “Errorsea” // Ans: string
typeof 200 // Ans: number
typeof NaN // Ans: number
typeof true // Ans: boolean
typeof [1, 2, 4, 7] // Ans: object
typeof {name:’Errorsea’, age:18} // Ans: object
typeof new Date() // Ans: object
typeof null // Ans: object
typeof Bike // Ans: undefined (if Bike is not declared)
typeof function () {} // Ans: function

9) Delete Operator

It used to delete properties of objects in javascript.

Example:

var person = {firstName:”Nick”, age:18, Color:”white”};
delete person[“Color”];

The above code deletes the Color property from the object person.

Note: We cannot use the deleted property in the code without adding it again.

10) The in Operator

It is used to check the specified property in the object.
This operator returns true if the specified property is present in the object.

Example:

var person = {firstName:”Nick”, age:18, Color:”white”};
var x = age in person; // Ans: true
var x = Birthdate in person; //Ans: false

11) The instance of Operator

It is used for checking whether the specified object is an instance of in the object or not. This operator returns true if the specified property is an instance of the object.

Example:

var media = [“facebook”, “whatsapp”, “instagram”];
media instanceof Array; // Ans: true
media instanceof String; // Ans: false
media instanceof Object; // Ans: true
media instanceof Number; // Ans: false

12) The void Operator

This operator is mostly used to get undefined primitive value using void(0) in javascript. It evaluates the expression and returns undefined.

Example:

<a href=”javascript:void(0)”>I am useless link</a>

13) Assignment Operator

It is used to assign value to the Javascript variable.
It is denoted by ‘ = ’ sign.

Example:

var m = “Errorsea”;
var n = 5;

Note: Javascript also supports shorthand notations with assignment operators.

Types of Assignment Operators

OperationsDescriptionSame as (here m = 8, n = 2 )
m = nassignmentm = n // Ans: m=2
m += nAdditionm = m + n // Ans: m=10
m -= nSubtractionm = m – n // Ans: m=6
m *= nMultiplicationm = m * n // Ans: m=16
m /= nDivisionm = m / n // Ans: m=4
m %= nModulusm = m % n // Ans: m=0

Conclusion

These are the different types of operators used in javascript according to the requirements for providing users the better facilities. User can take actions according to the result of different operators.

Leave a Reply

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

More in JavaScript
javascript string methods
JavaScript String Methods

What is the String? The string is a collection of one or more characters written inside quotes. Example: var m...

Close