JavaScript Me Operators Kya Hote Hain?
JavaScript me operators ka use calculations, comparisons, aur logical operations ke liye hota hai. Operators ka alag-alag type hota hai jo different tasks perform karte hain. Niche sabhi important operators ke baare me detail me samjhaya gaya hai.
1. Arithmetic Operators:
Arithmetic operators JavaScript ya kisi bhi programming language me mathematical calculations perform karne ke liye use hote hain. Ye operators numbers par kaam karte hain aur addition (+
), subtraction (-
), multiplication (*
), division (/
), modulus (%
), exponentiation (**
), aur increment (++
) aur decrement (--
) jaise operations ko execute karte hain. Ye operators numerical expressions evaluate karne aur mathematical computations karne me madad karte hain. Arithmetic operators bina kisi complex logic ke basic aur advanced mathematical calculations karne ki suvidha dete hain, jisme priority rules (operator precedence) ka bhi dhyan rakha jata hai, jisme multiplication aur division ki priority addition aur subtraction se zyada hoti hai.
Operator | Kaam (Function) | Example | Output |
---|---|---|---|
+ (Addition) | Do numbers ko jodne ke liye | 10 + 5 | 15 |
– (Subtraction) | Ek number ko doosre se ghatane ke liye | 10 – 5 | 5 |
* (Multiplication) | Do numbers ko multiply karne ke liye | 10 * 5 | 50 |
/ (Division) | Ek number ko doosre se divide karne ke liye | 10 / 5 | 2 |
% (Modulus) | Ek number ko doosre se divide karne ke baad remainder dikhata hai | 10 % 3 | 1 |
** (Exponentiation) | Power calculate karne ke liye | 2 ** 3 | 8 |
++ (Increment) | Value ko 1 se badhata hai | let x = 5; x++ | 6 |
— (Decrement) | Value ko 1 se kam karta hai | let y = 5; y– | 4 |
Example:
let a = 10;
let b = 3;
console.log(a + b); // 13
console.log(a % b); // 1
2. Comparison Operators:
Comparison operators JavaScript aur anya programming languages me do values ko compare karne ke liye use hote hain. Ye operators values ke bich relation check karte hain, jaise ki barabar (==
), strictly barabar (===
), bada (>
), chhota (<
), bada ya barabar (>=
), chhota ya barabar (<=
), aur barabar nahi (!=
ya !==
). Yeh logical expressions return karte hain jo true
ya false
hote hain. Comparison operators numerical, string, aur boolean values ke sath kaam karte hain. Strict comparison (===
aur !==
) data type bhi check karta hai, jabki loose comparison (==
aur !=
) type conversion karta hai.
Operator | Kaam (Function) | Example | Output |
---|---|---|---|
== (Equal to) | Agar dono values equal hain to true return karega | 10 == “10” | true |
=== (Strict equal to) | Data type aur value dono check karega | 10 === “10” | false |
!= (Not equal) | Agar values alag hain to true dega | 10 != 5 | true |
!== (Strict not equal) | Value aur type dono different hone chahiye | 10 !== “10” | true |
> (Greater than) | Pehla number dusre se bada hai ya nahi | 10 > 5 | true |
< (Less than) | Pehla number dusre se chhota hai ya nahi | 10 < 5 | false |
>= (Greater than or equal to) | Pehla number bada ya equal hai ya nahi | 10 >= 10 | true |
<= (Less than or equal to) | Pehla number chhota ya equal hai ya nahi | 5 <= 10 | true |
Example:
console.log(10 > 5); // true
console.log(5 == "5"); // true
console.log(5 === "5"); // false
3. Logical Operators:
Logical operators JavaScript aur doosri programming languages me logical operations perform karne ke liye use hote hain. Ye operators multiple conditions ko evaluate karne aur unke results ko combine karne me madad karte hain. Logical operators mainly teen types ke hote hain: AND (&&
), OR (||
), aur NOT (!
). AND operator tabhi true
return karta hai jab dono conditions true
hon, OR operator ek bhi condition true
hone par true
return karta hai, aur NOT operator kisi bhi value ka opposite result return karta hai. Yeh operators decision making aur conditional statements me kaafi useful hote hain.
Operator | Kaam (Function) | Example | Output |
---|---|---|---|
&& (AND) | Dono conditions true honi chahiye | (10 > 5 && 10 < 20) | true |
|| (OR) | Koi bhi ek condition true ho sakti hai | (10 > 5 || 8 > 15) | true |
! (NOT) | Condition ko ulta kar deta hai | !(10 > 5) | false |
Examples:
let a = 10, b = 20;
console.log(a > 5 && b > 15); // true (both true)
console.log(a > 15 || b > 15); // true (one true)
console.log(!(a > 5)); // false (negates true)
4. Assignment Operators:
Assignment operators ek tarah ke operators hote hain jo ek variable ko value assign karne ke liye use kiye jate hain. Yeh operators kisi variable me existing value ko modify karne ya naye values assign karne me madad karte hain. Basic assignment operator =
hota hai, jo ek variable ko kisi value ke equal banata hai. Iske alawa, compound assignment operators jaise +=
, -=
, *=
, /=
, aur %=
bhi hote hain, jo variable ki current value ko kisi naye value ke saath update karte hain. Yeh operators coding ko short aur efficient banane me madad karte hain.
Operator | Kaam (Function) | Example | Equivalent to |
---|---|---|---|
= | Value assign karta hai | x = 10 |
x = 10 |
+= | Pehle wali value me naya value add karta hai | x += 5 |
x = x + 5 |
-= | Pehle wali value me se naya value minus karta hai | x -= 5 |
x = x - 5 |
*= | Pehle wali value ko multiply karta hai | x *= 5 |
x = x * 5 |
/= | Pehle wali value ko divide karta hai | x /= 5 |
x = x / 5 |
%= | Pehle wali value ko remainder se update karta hai | x %= 5 |
x = x % 5 |
**= | Pehle wali value ko power se update karta hai | x **= 2 |
x = x ** 2 |
Example :
let x = 10; // Simple assignment
x += 5; // x = x + 5 → x = 15
x -= 3; // x = x – 3 → x = 12
x *= 2; // x = x * 2 → x = 24
x /= 4; // x = x / 4 → x = 6
x %= 5; // x = x % 5 → x = 1
x **= 3; // x = x ** 3 → x = 1
5. Bitwise Operators :
Operator | Kaam (Function) | Example | Output (Binary Form) |
---|---|---|---|
& (Bitwise AND) | Dono bits 1 honi chahiye tabhi result 1 aayega | 5 & 3 | 101 & 011 = 001 (1) |
| (Bitwise OR) | Koi bhi ek bit 1 ho to result 1 aayega | 5 | 3 | 101 | 011 = 111 (7) |
^ (Bitwise XOR) | Sirf alag-alag bits pe 1 aayega, same bits par 0 hoga | 5 ^ 3 | 101 ^ 011 = 110 (6) |
~ (Bitwise NOT) | Bits ko reverse (0 to 1, 1 to 0) kar deta hai | ~5 | ~00000101 = 11111010 (-6 in two’s complement form) |
<< (Left Shift) | Bits ko left shift karta hai (naya zero add hota hai right side se) | 5 << 1 | 101 << 1 = 1010 (10) |
>> (Right Shift) | Bits ko right shift karta hai (left side se sign bit add hota hai) | 5 >> 1 | 101 >> 1 = 10 (2) |
>>> (Unsigned Right Shift) | Sirf bits ko right shift karta hai (sign bit consider nahi karta) | -5 >>> 1 | 11111111111111111111111111111011 >>> 1 = 01111111111111111111111111111101 (2147483645 in 32-bit system) |
6. Ternary Operator:
Ternary Operator ek conditional operator hai jo ek short-hand if-else statement provide karta hai. Isme teen parts hote hain: condition, true case, aur false case. Agar condition true hoti hai to first expression execute hota hai, aur agar false hoti hai to second expression execute hota hai. Iska syntax hai:condition ? expression_if_true : expression_if_false;
Ye concise aur readable code likhne ke liye use hota hai, jisme ek simple if-else statement ek line me likha ja sakta hai.
let age = 18;
let result = (age >= 18) ? "Adult" : "Minor";
console.log(result); // "Adult"
JavaScript me operators programming ka ek important hissa hain. Ye hume calculations, comparisons, logical operations aur assignments me madad karte hain. JavaScript me sahi operators ka use karna ek acchi coding practice hai, jo hamare code ko short aur efficient banata hai.
Quiz: Test Your Knowledge on JavaScript Operators
Bonus: Practical Application!
Aaj hi JavaScript operators ka istemal karke coding ko aur bhi behtar banayein!
JavaScript me operators ko sahi tareeke se samajhne ke liye different types jaise arithmetic, assignment, comparison, logical, bitwise, ternary, aur typeof operators ka upayog karein aur apni coding skills ko next level par le jaayein.