JavaScript Operators Overview
JavaScript Operators are symbols that perform operations on values and variables — like adding numbers, comparing values, or combining strings.
Types of JavaScript Operators
1. Arithmetic Operators
Used for basic mathematical calculations.
Operator | Description | Example | Result |
---|---|---|---|
+ | Addition | 5 + 2 | 7 |
- | Subtraction | 5 - 2 | 3 |
* | Multiplication | 5 * 2 | 10 |
/ | Division | 10 / 2 | 5 |
% | Modulus (Remainder) | 10 % 3 | 1 |
** | Exponentiation (Power) | 2 ** 3 | 8 |
++ | Increment | x++ | Adds 1 |
-- | Decrement | x-- | Subtracts 1 |
2. Assignment Operators
Used to assign or update variable values.
Operator | Example | Same As |
---|---|---|
= | x = 5 | Assigns 5 to x |
+= | x += 2 | x = x + 2 |
-= | x -= 2 | x = x - 2 |
*= | x *= 2 | x = x * 2 |
/= | x /= 2 | x = x / 2 |
%= | x %= 2 | x = x % 2 |
3. Comparison Operators
Used to compare two values — returns a Boolean (true
or false
).
Operator | Description | Example | Result |
---|---|---|---|
== | Equal (loose) | 5 == "5" | true |
=== | Strict Equal (checks type too) | 5 === "5" | false |
!= | Not Equal | 5 != 3 | true |
!== | Strict Not Equal | 5 !== "5" | true |
> | Greater Than | 7 > 3 | true |
< | Less Than | 7 < 3 | false |
>= | Greater or Equal | 5 >= 5 | true |
<= | Less or Equal | 3 <= 5 | true |
4. Logical Operators
Used to combine multiple conditions.
Operator | Description | Example | Result |
---|---|---|---|
&& | AND | x > 5 && y < 10 | true if both true |
` | ` | OR | |
! | NOT | !(x > 5) | Opposite of condition |
5. Bitwise Operators
Operate on binary numbers.
Operator | Description | Example |
---|---|---|
& | AND | 5 & 1 → 1 |
` | ` | OR |
^ | XOR | 5 ^ 1 → 4 |
~ | NOT | ~5 → -6 |
<< | Left shift | 5 << 1 → 10 |
>> | Right shift | 5 >> 1 → 2 |
>>> | Zero-fill right shift | 5 >>> 1 → 2 |
6. String Operators
Used to join (concatenate) strings.
let first = "Hello";
let last = "World";
console.log(first + " " + last); // Hello World
7. Ternary (Conditional) Operator
Shortcut for if...else
statements.
let age = 18;
let result = (age >= 18) ? "Adult" : "Minor";
console.log(result); // Adult
8. Type Operators
Used to check or convert data types.
Operator | Description | Example | Result |
---|---|---|---|
typeof | Returns variable type | typeof "Hello" | "string" |
instanceof | Checks object type | arr instanceof Array | true |