JavaScript Operators
🧠 What Are JavaScript Operators?
JavaScript operators are symbols used to perform operations on values and variables.
Example:
🔹 Types of JavaScript Operators
1️⃣ Arithmetic Operators
Used for mathematical calculations.
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ |
Addition | 10 + 5 |
15 |
- |
Subtraction | 10 - 5 |
5 |
* |
Multiplication | 10 * 5 |
50 |
/ |
Division | 10 / 5 |
2 |
% |
Modulus (remainder) | 10 % 3 |
1 |
** |
Exponent | 2 ** 3 |
8 |
2️⃣ Assignment Operators
Used to assign or update values.
| Operator | Meaning | Example | Result |
|---|---|---|---|
= |
Assign | x = 10 |
10 |
+= |
Add and assign | x += 5 |
x = x + 5 |
-= |
Subtract and assign | x -= 5 |
x = x - 5 |
*= |
Multiply and assign | x *= 5 |
x = x * 5 |
3️⃣ Comparison Operators
Used to compare two values (returns true or false).
| Operator | Meaning | Example | Result |
|---|---|---|---|
== |
Equal to | 10 == "10" |
true |
=== |
Strict equal | 10 === "10" |
false |
!= |
Not equal | 10 != 5 |
true |
> |
Greater than | 10 > 5 |
true |
< |
Less than | 5 < 10 |
true |
>= |
Greater or equal | 10 >= 10 |
true |
<= |
Less or equal | 5 <= 10 |
true |
4️⃣ Logical Operators
Used to combine conditions.
| Operator | Meaning | Example | Result |
|---|---|---|---|
&& |
AND | true && false |
false |
|
OR | ||
! |
NOT | !true |
false |
5️⃣ String Operators
Only + and += work for strings.
6️⃣ Increment and Decrement Operators
| Operator | Meaning | Example |
|---|---|---|
++ |
Increase by 1 | x++ |
-- |
Decrease by 1 | x-- |
📌 Example with Output
Output:
⭐ Summary
JavaScript operators help perform:
-
Math operations
-
Assign values
-
Compare values
-
Combine conditions
-
Manipulate strings
