JavaScript Operators are symbols that have a special meaning which make JavaScript engine to perform some action on operands. For example: the addition +
symbol is an operator means to add two variables or values, while the equal-to ==
, greater-than >
or less-than <
symbols used to compare two variables or values.
There are following types of operators in JavaScript.
The Arithmetic operators are used to perform arithmetic operations, like addition
, subtraction
, multiplication
, etc.
Operator Name | Operator | Example |
---|---|---|
Addition | + | 10 + 20 = 30 |
Subtraction | - | 20 - 10 = 10 |
Multiplication | * | 10 * 5 = 50 |
Division | / | 50 / 5 = 10 |
Modulus (Remainder) | % | 20 % 2 = 0 |
The comparison operators are used to compare
two values (number or string):
Operator Name | Operator | Example |
---|---|---|
Equal to | == | 10 == 20 = false |
Identical (equal and of same type) | === | 10 === 20 = false |
Not equal | != | 10 != 20 = true |
Not Identical | !== | 20 !== 20 = false |
Greater than | > | 20 < 10 = true |
Less than | < | 20 > 10 = false |
Greater than or equal to | >= | 20 >= 10 = true |
Less than or equal to | <= | 20<=10 = false |
The Assignment operators '='
is used with numeric values to assign a value to a variable.There are various ways to assign a value to a variable-
Operator | Same as.. | Use for |
---|---|---|
x = y | x = y | Assign |
x += y | x = x + y | Addition |
x -= y | x = x - y | Subtraction |
x *= y | x = x * y | Multiplication |
x /= y | x = x / y | Division |
x %= y | x = x % y | Modulus |
The logical operators are used to combine conditional statements
. Suppose we have two conditional statements 'x' and 'y':-
Operator Name | Operator | Use |
---|---|---|
Logical AND | && | True if both x and y are true |
Logical OR | || | True if either x or y is true |
logical Not | ! | True if x is not true |
Operator Name | Operator | Use |
---|---|---|
Concatenation | + | Appends str2 to str1. |
Concatenation assignment | += | Appends str2 to the str1. |
The increment/decrement operators are used to increment/decrement a variable's value by '1'
.
Operator Name | Operator | Use |
---|---|---|
Pre-increment | ++x | Increments x by one, then returns x |
Post-increment | x++ | Returns x, then increments x by one |
Pre-decrement | --x | Decrements x by one, then returns x |
Post-decrement | x-- | Returns x, then decrements x by one |
The bitwise operators perform bitwise operations on operands.
Operator | Operator Name | Example | Same as (Binary) | Result | Decimal |
---|---|---|---|---|---|
& | Bitwise AND | 5 & 1 | 0101 & 0001 | 0001 | 1 |
| | Bitwise OR | 5 | 1 | 0101 | 0001 | 0101 | 5 |
~ | Bitwise Not | ~ 5 | ~ 0101 | 1010 | 10 |
^ | Bitwise XOR | 5 ^ 1 | 0101 ^ 0001 | 0100 | 4 |
<< | Bitwise Left Shift | 5 << 1 | 0101 << 0001 | 1010 | 10 |
>> | Bitwise Right Shift | 5 >> 1 | 0101 >> 0001 | 0010 | 2 |
>>> | Bitwise Zero Right Shift | 5 >>> 1 | 0101 >>> 0001 | 0010 | 2 |
The following operators are known as JavaScript special operators.
Operator | Description |
---|---|
, | It allows multiple expressions to be evaluated as single statement. |
yield | This operator checks what is returned in a generator by the generator's iterator. |
(?:) | Conditional Operator returns value based on the condition. It can be used in place of 'if' statement. |
in | It checks if object has the given property. |
delete | It deletes a property from the object. |
instanceof | Checks if the object is an instance of given type. |
void | It discards the expression's return value. |
typeof | Checks the type of object. |
List of color names supported by all browser »
List of character codes to display special character »
List of all language supported by all browser »
List of Country code supported by all browser »