Operators in JavaScript are special symbols or keywords that are used to perform operations on operands (values and variables). They are essential in every JavaScript program to perform mathematical, logical, or assignment operations.
These operators are used to perform arithmetic calculations such as addition, subtraction, multiplication, etc.
| Operator | Description | Example | Output |
|---|---|---|---|
| + | Addition | let x = 5 + 3; | 8 |
| - | Subtraction | let x = 5 - 3; | 2 |
| * | Multiplication | let x = 5 * 3; | 15 |
| / | Division | let x = 6 / 3; | 2 |
| % | Modulus (remainder) | let x = 7 % 3; | 1 |
| ** | Exponentiation | let x = 2 ** 3; | 8 |
These operators are used to compare two values and return a Boolean value (true or false).
| Operator | Description | Example | Output |
|---|---|---|---|
| == | Equal to | 5 == '5' | true |
| === | Strict equal to (value and type) | 5 === '5' | false |
| != | Not equal | 5 != '6' | true |
| !== | Strict not equal | 5 !== '5' | true |
| > | Greater than | 6 > 3 | true |
| < | Less than | 2 < 5 | true |
| >= | Greater than or equal to | 5 >= 5 | true |
| <= | Less than or equal to | 4 <= 3 | false |
Used to combine multiple conditions or expressions and return Boolean results.
| Operator | Description | Example | Output |
|---|---|---|---|
| && | Logical AND | (5 > 2) && (4 < 10) | true |
| || | Logical OR | (5 < 2) || (4 < 10) | true |
| ! | Logical NOT | !(5 === 5) | false |
Used to assign values to variables and combine with arithmetic operations.
| Operator | Description | Example | Output |
|---|---|---|---|
| = | Assign | x = 10 | 10 |
| += | Add and assign | x += 5 | 15 |
| -= | Subtract and assign | x -= 2 | 13 |
| *= | Multiply and assign | x *= 2 | 26 |
| /= | Divide and assign | x /= 2 | 13 |
| %= | Modulus and assign | x %= 4 | 1 |
Perform bit-level operations on binary representations of integers.
| Operator | Description | Example | Output |
|---|---|---|---|
| & | Bitwise AND | 5 & 3 | 1 |
| | | Bitwise OR | 5 | 3 | 7 |
| ^ | Bitwise XOR | 5 ^ 3 | 6 |
| ~ | Bitwise NOT | ~5 | -6 |
| << | Left Shift | 5 << 1 | 10 |
| >> | Right Shift | 5 >> 1 | 2 |