JavaScript Operators

JavaScript में operators का उपयोग values पर कोई operation (क्रिया) करने के लिए किया जाता है — जैसे जोड़ना, घटाना, तुलना करना, या किसी logic को लागू करना।

इस chapter में आप सीखेंगे:

  • Operators क्या होते हैं
  • उनके प्रकार (Types of Operators)
  • हर operator के उदाहरण और उपयोग
  • अभ्यास प्रश्न

JavaScript Operators के मुख्य प्रकार

Operator TypeDescription
Arithmetic Operatorsगणनाएँ जैसे जोड़, घटाव, गुणा, भाग
Assignment Operatorsकिसी value को assign करने के लिए
Comparison Operatorsदो values की तुलना के लिए
Logical Operatorsकई conditions को जोड़ने के लिए
String OperatorsStrings को जोड़ने (concatenate) के लिए
Unary / Type Operatorsएक ही operand पर काम करते हैं
Ternary OperatorShort form में condition check करने के लिए
Bitwise OperatorsBinary level पर operations

1. Arithmetic Operators

ये operators संख्याओं पर गणना करने के लिए होते हैं:

OperatorMeaningExampleResult
+Addition5 + 38
-Subtraction5 - 23
*Multiplication4 * 28
/Division10 / 25
%Modulus10 % 31
**Exponentiation2 ** 38
++Incrementx++बढ़ाए 1
--Decrementx--घटाए 1

2. Assignment Operators

किसी variable में value assign करने के लिए:

OperatorMeaningExampleSame As
=Assignx = 5
+=Add and assignx += 3x = x + 3
-=Subtract and assignx -= 2x = x - 2
*=Multiply and assignx *= 4x = x * 4
/=Divide and assignx /= 2x = x / 2
%=Modulus and assignx %= 2x = x % 2

3. Comparison Operators

दो values की तुलना करके Boolean (true/false) result देते हैं:

OperatorMeaningExampleResult
==Equal to (value)5 == '5'true
===Equal to (value + type)5 === '5'false
!=Not equal to (value)4 != 3true
!==Not equal to (value + type)4 !== '4'true
>Greater than7 > 5true
<Less than3 < 4true
>=Greater than or equal5 >= 5true
<=Less than or equal4 <= 6true

4. Logical Operators

कई conditions को जोड़ने या check करने के लिए:

OperatorNameExampleResult
&&ANDtrue && truetrue
``OR
!NOT!truefalse

5. String Operators

Strings को जोड़ने के लिए + का उपयोग किया जाता है:

let first = "Hello ";
let second = "World!";
let result = first + second;
console.log(result); // Output: Hello World!

6. Type & Unary Operators

🔸 typeof

Variable की data type को बताता है:

typeof "Hello"     // "string"
typeof 123         // "number"
typeof true        // "boolean"

🔸 Unary -, +

let x = "5";
let y = +x;  // Converts string to number

7. Ternary Operator

Condition को short form में check करने के लिए:

let age = 18;
let status = (age >= 18) ? "Adult" : "Minor";
console.log(status); // Output: Adult

8. Bitwise Operators (Advanced)

Binary level पर operations के लिए — आमतौर पर rarely use होते हैं।

OperatorName
&AND
``
^XOR
~NOT
<<Left shift
>>Right shift

अभ्यास प्रश्न

  1. == और === में क्या अंतर है?
  2. नीचे दिए गए expression का result क्या होगा? let x = 5; x += 3; console.log(x);
  3. typeof null का result क्या आता है?
  4. Ternary operator का syntax क्या होता है?
  5. नीचे दिए गए code का output बताइए: let a = "10"; let b = 10; console.log(a == b); // ? console.log(a === b); // ?