JavaScript Me Operators Kya Hote Hain?
Calculations, Comparisons, aur Logical Operations Perform Karna Sikhein.
1. Arithmetic Operators
Arithmetic operators ka use mathematical calculations (jodne, ghatane, guna, bhaag) ke liye hota hai.
Operator | Kaam (Function) | Example | Output |
---|---|---|---|
+ | Jodne ke liye (Addition) | 10 + 5 | 15 |
- | Ghatane ke liye (Subtraction) | 10 - 5 | 5 |
* | Guna karne ke liye (Multiplication) | 10 * 5 | 50 |
/ | Bhaag karne ke liye (Division) | 10 / 5 | 2 |
% | Remainder nikalne ke liye (Modulus) | 10 % 3 | 1 |
** | Power calculate karne ke liye (Exponentiation) | 2 ** 3 | 8 |
++ | Value ko 1 se badhata hai (Increment) | let x = 5; x++ | 6 |
-- | Value ko 1 se kam karta hai (Decrement) | let y = 5; y-- | 4 |
2. Comparison Operators
Comparison operators ka use do values ko compare karne ke liye hota hai. Inka result hamesha true
ya false
hota hai.
Operator | Kaam (Function) | Example | Output |
---|---|---|---|
== | Equal to (sirf value check) | 10 == "10" | true |
=== | Strictly equal to (value aur type dono check) | 10 === "10" | false |
!= | Not equal | 10 != 5 | true |
!== | Strictly not equal | 10 !== "10" | true |
> | Greater than | 10 > 5 | true |
< | Less than | 10 < 5 | false |
>= | Greater than or equal to | 10 >= 10 | true |
<= | Less than or equal to | 5 <= 10 | true |
3. Logical Operators
Logical operators ka use multiple conditions ko combine karne ke liye hota hai.
Operator | Kaam (Function) | Example |
---|---|---|
&& (AND) | Dono conditions true honi chahiye | (10 > 5 && 10 < 20) |
|| (OR) | Koi bhi ek condition true honi chahiye | (10 > 5 || 8 > 15) |
! (NOT) | Condition ko ulta kar deta hai | !(10 > 5) |
4. Assignment Operators
Assignment operators ka use variables ko value assign karne ke liye hota hai.
Operator | Example | Equivalent to |
---|---|---|
= | x = 10 | x = 10 |
+= | x += 5 | x = x + 5 |
-= | x -= 5 | x = x - 5 |
*= | x *= 5 | x = x * 5 |
/= | x /= 5 | x = x / 5 |
5. Ternary Operator
Yeh if-else statement ka ek shortcut hai.
let age = 20;
let canVote = (age >= 18) ? "Yes, can vote" : "No, cannot vote";
console.log(canVote); // Output: Yes, can vote
Key Takeaways
- Arithmetic Operators: Basic math ke liye (+, -, *, /).
- Comparison Operators: Values ko compare karne ke liye (>, <, ==, ===). Hamesha `true` ya `false` return karte hain.
- Logical Operators: Conditions ko combine karne ke liye (&&, ||, !).
- Assignment Operators: Variables ko value dene ke liye (=, +=, -=).
- Ternary Operator: Simple if-else logic ke liye ek shortcut.
Bonus: Practical Application!
Ab in operators ko practically use karke dekhein.
Do numbers par arithmetic aur comparison operators apply karke unka result `console.log()` me check karein.
Practice in JS EditorTest Your Knowledge!
Kya aap JavaScript Operators ke baare mein seekh chuke hain? Chaliye dekhte hain!
Apni knowledge test karne ke liye is quick quiz ko dein.
Start Quiz