Operators
JavaScript has following operator categories
Arithmetic Operators
Operator | Description | JS Example |
---|
+ | Addition | a + b |
– | Subtraction | a - b |
* | Multiplication | a * b |
** | Exponentiation | a ** b |
/ | Division | a / b |
% | Modulus | a % b |
++ | Increment | a++ |
— | Decrement | a-- |
Assignment Operators
Operator | Description | JS Example | Equivalent to |
---|
= | Assignment | a = 4 | |
+= | Addition Assignment | a += b | a = a + b; |
– | Subtraction Assignment | a -= b | a = a - b; |
* | Multiplication Assignment | a *= b | a = a * b; |
** | Exponentiation Assignment | a **= b | a = a ** b; |
/ | Division Assignment | a /= b | a = a / b; |
% | Modulus Assignment | a %= b | a = a % b; |
Comparison Operators
Operator | Description | JS Example |
---|
== | equal to | a == b |
=== | equal value and equal type | a === b |
!= | not equal | a != b |
!== | not equal value or not equal type | a !== b |
> | greater than | a > b |
< | less than | a < b |
>= | greater than or equal to | a >= b |
<= | less than or equal to | a <= b |
? | ternary operator | x = condition? a: b |
Logical Operators
Operator | Description | JS Example |
---|
&& | and | (a == 2) && (b == 5) |
|| | or | (a == 2) || (b == 5) |
! | not | !(a == 2) |
Type Operators
Operator | Description | JS Example |
---|
typeof | returns type of variable | a = 5; console.log(typeof a); |
instanceof | returns true if given object is an instance of specified type | var a = new String('apple'); console.log(a instanceof String); |
Bitwise Operators
Operator | Description | JS Example |
---|
& | AND | a & b |
| | OR | a | b |
~ | NOT | ~a |
^ | XOR | a ^ b |
<< | left shift | a << b |
>> | right shift | a >> b |
>>> | unsigned right shift | a >>> b |