JavaScript Operators
An operator is a symbol that is reserved for special tasks or operations. Operators are used to performing operations on the operands. The operands can be variables, numeric literals, or string literals. An operator can work on one or more than one operand.
Operators are useful for modifying data by performing operations on it. For example, if there are two variables a
and b
and we want to add the values of both of these variables, to do so we can use the arithmetic operator +
to perform the addition operation.
JavaScript supports a rich set of operators. These operators perform a specific task and every operator has different properties. The list of operators is given below:

Arithmetic Operators

Relational Operators

Assignment Operators

Bitwise Operators

Logical Operators

String Operators

Ternary Operator
Let's cover each one of these types one by one and see the different operators supported in JavaScript.
JavaScript Arithmetic Operators
Arithmetic operators in JavaScript are used to perform arithmetic operations or mathematical operations like addition, subtraction, multiplication, etc. All the arithmetic operators have been listed in the table below.
Operator  Description 

+ 
The

 
The It is also used to represent a negative number.

* 
The

/ 
The

% 
The

++ 
This operator is the increment operator. It is a unary operator which means it is used with a single operand. Using this operator you can add 1 to the existing value.

 
This operator is the decrement operator. It is a unary operator which means it is used with a single operand. Using this operator you can subtract 1 from the existing value.

JavaScript Relational Operators
These operators are used to perform comparisons between two operands. These operators return a boolean value as a result. We will use these operators when we will cover JavaScript if else statements.
Relational operators are also called Comparison operators as they are used to compare two values.
Operator  Description 

== 
It is the equality operator. It returns true if both operands are equal, otherwise returns false.

!= 
It is the "not equal to" operator. It returns true if both operands are not equal, otherwise returns false.

=== 
It is the strict equality operator. If operands are strictly equal(same value and same data type) with type conversion then it returns true otherwise false.
The first 

It returns true if operands on both sides of this operator are not equal/not of the same type.
The basic not equal to operator will treat the values of 
> 
It returns true if the lefthand side value is greater than the righthand side value, otherwise false.

>= 
It returns true if the lefthand side value is greater than or equal to the righthand side value otherwise it returns false.

< 
It returns true if the lefthand side value is less than the righthand side value, otherwise it returns false.

<= 
It returns true if the lefthand side value is less than or equal to the righthand side value, otherwise, it returns false.

JavaScript Assignment Operators
These are the operators used while assigning the values to the variables in JavaScript.
Apart from the main assignment operator =
, there are several other compound assignment operators using which you can perform some operation on the variable before assigning the value to it.
Operator  Description 

= 
It assigns the value to the lefthand side variable.

+= 
It adds the righthand side operand to the lefthand side operand and then assigns the result to the lefthand side operand.


It subtracts the righthand side operand from the lefthand side operand and then assigns the result to the lefthand side operand.

*= 
It multiplies the righthand side operand with the lefthand side operand and then assigns the result to the lefthand side operand.

/= 
It divides the lefthand side operand by the righthand side operand and assigns the result to the lefthand side operand.

%= 
It divides the lefthand side operand by the righthand side operand and then assigns the remainder to the lefthand side operand.

JavaScript Bitwise Operators
JavaScript supports the bitwise operators to perform bitwise operations on operands represented in the binary form. When you use the bitwise operators, the values are first converted into binary, and then the bitwise operator performs the operation on them.
Let's see the available bitwise operators in JavaScript.
Operator  Description 

& (AND) 
Sets each bit to 1 if both bits are 1, for everything else it will set the bit to 0.
In the above code, on the bits of 0101 and 0011, the 

Sets the bit to 1 if one of the two bits is 1. So
You can do the math now, for the above code. 
^ (XOR) 
XOR stands for exclusive OR. It sets each bit to 1 if and only if one of two bits is 1. If both bits are 1 or both bits are 0, then you get 0 bits.
In the above code, the last bit in both operands is 1, for which the 
~ (NOT) 
This operator inverts all the bits, which means 1 will be converted to 0, and 0 to 1. It works with a single operand.
In the code example above, each bit of 5, is converted into its opposite. 
<< (Zero Fill Left Shift) 
This operator shifts the bits to the left by a number of places specified by the second operator. It adds zeros in from the right end, letting the leftmost bit fall off.
It's like pushing off the left bits and adding more 0's from the right side. 
>> (Signed fill right shift) 
This operator shifts the bits right by pushing copies of the leftmost bit in from the left and lets the rightmost bit fall off. The leftmost bit is the sign bit, which is 0 for positive, and 1 for negative.
Two bits are removed from the right side, and two bits with value 0 are added from the left. 
>>> (Zero fill right shift) 
This operator shifts the bits right by the number of places specified by the second operator and adds zeroes from the left, letting the rightmost bit fall off.
One bit is shifted to the right, the rightmost bit falls off, and one 0 bit is added from the left. 
Bitwise operators can be used for various use cases in JavaScript, like:

You can represent user permissions in your web application as a combination of bits and can use bitwise operators to manage and check the permission. For example, if 0010 is a permission set indicator, in which 0's represents No permission, whereas 1's represents permission available, is a good way to manage permissions.

Bitwise operators can also be used for hashing and encoding data.
These are just two examples, there are many different use cases where bitwise operators can be used.
JavaScript Logical Operators
The logical operators in JavaScript are used to combine two or more boolean values or expressions using relational operators.
These operators are used in Flow control  if else conditional statements in JS.
Operator  Description 

&& (AND) 
It returns true only if both the operands are true otherwise it will return false.
The first expression 
 (OR) 
It returns true if either of the operands is true. It returns false when both operands are false.
The first expression 
! (NOT) 
It negates the operand, returns true if the operand is false, and viceversa. This operator is used with a single operand.
The expression 
JavaScript String Operators
The main operator here is the concatenation operator or the +
operator. This is not the arithmetic operator. The +
operator is used to join one or more string values together and is called the concatenation operator.
Let's see an example,
let app = "Studytonight";
let msg = "Welcomes you.";
console.log(x + y);
StudytonightWelcomes you.
You can further improve the output by adding a space or a hyphen between the two strings, using one more + operator like this,
let app = "Studytonight";
let msg = "Welcomes you.";
console.log(x + "  " + y);
Studytonight  Welcomes you.
You can also use the concatenation operator to join a string and a nonstring value. JavaScript parses will automatically convert the nonstring value into string and join the two values. Let's see an example,
let a = "1"; // string
let b = 1; // number
console.log(a + b); // 11
11
This is a very popular example in JavaScript. Here, one value is a string and the other one is a number, so the number value is converted into a string, and then both the strings are joined together.
JavaScript Ternary Operator (?:)
The ternary operator is used to implement conditional checks in JavaScript. You can say that it is a shorthand style of ifelse conditions.
The syntax to use this operator is:
(CONDITION) ? <EXECUTE IF TRUE> : <EXECUTE IF FALSE>
So you use a condition or an expression that can return true or false value. If the value returned is true then the code statement before the :
(colon) gets executed, otherwise the code statement after the :
(colon) gets executed.
Let's see an example,
let a = 10;
let b = 11;
(a > b) ? console.log("A is greater than B") : console.log("A is less than B")
A is less than B
You can only add a single line code statement on both sides of the colon (:
).
JavaScript Operator Precedence and Associativity
Operator precedence determines the order in which operators are evaluated. Operators with higher precedence are evaluated first. For example, the expression (3+4*5)
, returns 23, because of the multiplication operator(*
) having higher precedence than addition(+
). Thus *
must be evaluated first.
Operator associativity determines the order in which the operators of the same precedence are processed. For example, assignment operators are rightassociative, so you can write a=b=5
, and with this statement, a
and b
are assigned the value 5.
The following table shows the precedence and associativity of operators in JavaScript. In this table, precedence is from bottom to top i.e. items at the bottom have low precedence, and precedence increases as we move to the top of the table.
Operator type  Operator (Symbol)  Associativity 

Member 

lefttoright 
Create new object  new 
righttoleft 
Function call  () 
lefttoright 
Increment  ++ 

Decrement   

Logical NOT  ! 
righttoleft 
Bitwise NOT  ~ 
righttoleft 
Unary +  + 
righttoleft 
Unary negation   
righttoleft 
typeof  typeof 
righttoleft 
void  void 
righttoleft 
Delete  delete 
righttoleft 
Multiplication  * 
left to right 
Division  / 
left to right 
Modulus  % 
left to right 
Addition  + 
left to right 
Subtraction   
left to right 
Bitwise Shift 

left to right 
Relational 

left to right 
in  in 
left to right 
instanceof  instanceof 
left to right 
Equality 

left to right 
Bitwise AND  & 
left to right 
Bitwise XOR  ^ 
left to right 
Bitwise OR   
left to right 
Logical AND  && 
left to right 
Logical OR   
left to right 
Ternary operator  ?: 
right to left 
Assignment 

right to left 
Comma  , 
left to right 
So that's it about operators in JavaScript. We have covered all the categories of operators and all the operators in JavaScript in this tutorial. Now it is your time to practice all of them.