JavaScript में Operators का उपयोग values पर operations perform करने के लिए किया जाता है। Operators की मदद से हम calculation कर सकते हैं, values compare कर सकते हैं, logic बना सकते हैं और variables में data assign कर सकते हैं।
Simple language में कहें तो operator वह symbol होता है जो JavaScript को बताता है कि data के साथ क्या करना है।
Beginner के लिए JavaScript Operators को समझना बहुत जरूरी है, क्योंकि almost हर JavaScript program में operators का use होता है।
Javascript Operators के प्रकार
JavaScript में operators को अलग-अलग categories में divide किया गया है:
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- String Operators
- Type Operators
अब हम इन सभी operators को एक-एक करके detail में समझते हैं।
Arithmetic Operators
Arithmetic operators numbers पर mathematical calculation करने के लिए use होते हैं।
Common Arithmetic Operators
+Addition-Subtraction*Multiplication/Division%Modulus++Increment--Decrement
Addition Operator (+)
Addition operator दो numbers को जोड़ने के लिए use होता है।
Example: Addition Operator
<script>
let a = 10;
let b = 5;
let sum = a + b;
</script>
यह code a और b की values को add करता है।
10 + 5 का result 15 होता है, जो sum variable में store हो जाता है।
इस code का final result memory में sum = 15 होगा।
Subtraction Operator (-)
Subtraction operator एक number में से दूसरा number minus करता है।
Example: Subtraction Operator
<script>
let x = 20;
let y = 8;
let result = x - y;
</script>
यह code 20 - 8 calculate करता है।
Result 12 होगा और result variable में store होगा।
Multiplication Operator (*)
Multiplication operator numbers को multiply करने के लिए use होता है।
Example: Multiplication Operator
<script>
let p = 4;
let q = 5;
let total = p * q;
</script>
यह code 4 * 5 calculate करता है।
Result 20 होगा और total variable में store होगा।
Division Operator (/)
Division operator एक number को दूसरे number से divide करता है।
Example: Division Operator
<script>
let num1 = 20;
let num2 = 4;
let output = num1 / num2;
</script>
यह code 20 / 4 calculate करता है।
Result 5 होगा और output variable में store होगा।
Modulus Operator (%)
Modulus operator division के बाद बचा हुआ remainder return करता है।
Example: Modulus Operator
<script>
let a = 10;
let b = 3;
let remainder = a % b;
</script>
यह code 10 को 3 से divide करता है।
3 * 3 = 9 होता है और remainder 1 बचता है।
Final result remainder = 1 होगा।
Increment Operator (++)
Increment operator variable की value को 1 से increase करता है।
Example: Increment Operator
<script>
let count = 5;
count++;
</script>
पहले count की value 5 है।
count++ के बाद value 6 हो जाती है।
Decrement Operator (–)
Decrement operator variable की value को 1 से decrease करता है।
Example: Decrement Operator
<script>
let number = 10;
number--;
</script>
पहले value 10 है।
number-- के बाद value 9 हो जाती है।
Assignment Operators
Assignment operators variables को value assign करने के लिए use होते हैं।
Common Assignment Operators
=+=-=*=/=
Assignment Operator (=)
Equal sign (=) value assign करने के लिए use होता है।
Example: Assignment Operator
<script>
let x = 10;
</script>
यह code x variable में value 10 assign करता है।
Add and Assign (+=)
+= operator value को add करके उसी variable में store करता है।
Example: += Operator
<script>
let x = 5;
x += 3;
</script>
यह code x = x + 3 के बराबर है।
Final result x = 8 होगा।
Comparison Operators
Comparison operators two values को compare करते हैं और result में true या false return करते हैं।
Common Comparison Operators
==Equal===Strict Equal!=Not Equal!==Strict Not Equal>Greater Than<Less Than>=Greater Than or Equal<=Less Than or Equal
Equal Operator (==)
== operator values को compare करता है, datatype check नहीं करता।
Example: Equal Operator
<script>
let result = (5 == "5");
</script>
यह code value compare करता है।
5 और "5" same value मानी जाती है, इसलिए result true होगा।
Strict Equal Operator (===)
=== operator value और datatype दोनों compare करता है।
Example: Strict Equal Operator
<script>
let result = (5 === "5");
</script>
यह code false return करेगा।
क्योंकि value same है लेकिन datatype different है।
Logical Operators
Logical operators conditions combine करने के लिए use होते हैं।
Common Logical Operators
&&AND||OR!NOT
AND Operator (&&)
&& operator तब true return करता है जब दोनों conditions true हों।
Example: AND Operator
<script>
let result = (10 > 5 && 8 > 3);
</script>
दोनों conditions true हैं, इसलिए result true होगा।
OR Operator (||)
|| operator तब true return करता है जब कोई एक condition true हो।
Example: OR Operator
<script>
let result = (10 < 5 || 8 > 3);
</script>
पहली condition false है, लेकिन दूसरी true है।
इसलिए result true होगा।
NOT Operator (!)
! operator condition का opposite result देता है।
Example: NOT Operator
<script>
let isActive = false;
let result = !isActive;
</script>
isActive false है, लेकिन !isActive true हो जाएगा।
String Operators
JavaScript में + operator strings को जोड़ने के लिए भी use होता है।
Example: String Concatenation
<script>
let firstName = "Amit";
let lastName = "Kumar";
let fullName = firstName + " " + lastName;
</script>
यह code strings को जोड़ता है।
Final result fullName = "Amit Kumar" होगा।
Type Operators
Type operators variable का type check करने के लिए use होते हैं।
typeof Operator
typeof operator variable का datatype बताता है।
Example: typeof Operator
<script>
let x = 10;
console.log(typeof x);
</script>
यह code x का datatype check करता है।
Output console में "number" दिखाई देगा।
JavaScript Operators का सही उपयोग
JavaScript operators program को powerful बनाते हैं।
Operators की सही understanding से आप:
- Calculations कर सकते हैं
- Conditions बना सकते हैं
- Logic develop कर सकते हैं
- Clean और efficient code लिख सकते हैं
JavaScript सीखने के लिए operators का strong knowledge बहुत जरूरी है।
