Operators in Javascript in Hindi जावास्क्रिप्ट ऑपरेटर्स क्या है?

Javascript Operators in Hindi

अन्य programming language की तरह javascript में भी operators होतें हैं | arithmetic operation करना या फिर variable में value assign करना या फिर दो values में comparison करना ये सब काम Operators के जरिये किया जाता है |

Types of Javascript Operators

javascript में कई तरह के operators हैं और वो हैं

  1. Arithmetic
  2. Comparison
  3. Logical
  4. Assignment
  5. Conditional

Arithmetic Operators

operands के बिच में mathmetical operation करने के लिए arithmetic operators का इस्तेमाल होता है |

उदाहरण के लिए दो variables लेते हैं a और b | let a= 100; let b =10;

ऑपरेटर्सनाम विवरण
+additionये दो या अधिक operands की addition करता है
उदाहरण : a + b // result : 110
substractionये पेहले operand से दुसरे operand को substract करता है
उदाहरण : a – b // result : 90
*multiplicationoperands को गुणा(multiply) करता है
उदाहरण : a * b // result : 1000
/divisionपहले operand से दुसरे को भाग(divide) करता है |
उदाहरण : a / b //result :10
%moduloइस operand से reminder निकाला जाता है
उदाहरण : a % b //result : 0
++incrementइससे operand की value, 1 value से बढती है |
उदाहरण : a ++ //result : 101
– –decrementइससे operand की value, 1 value से घटती है |
उदाहरण : a – – //result : 99

**नॉटपॉइंट अगर + operator दो integer values के ली गयी हो तो ये addition करता है | पर अगर एक भी operand string हुआ तो ये concatenation करता है | concatenation में सारे values को एक साथ मिलाकर दिखता है |

उदाहरण

let a = 10; 
let b=20;
let c="apple";
var res= a+b; //output-> 30
res = a+b+c //output-> 1020apple

Comparison Operators

comparison operator left side की operand से right side की operand को compare करती है और result में true या false बताती है | comparison operators का उपयोग if statements में होता है जिससे फिर अलग अलग condition लगाने में मदद मिलती है |

comparison operators list:

ऑपरेटर्सनाम विवरण
==comparison without typeleft वाली value right value से equal है या नहीं | अगर value equal हुई तो result true आएगी अगर नहीं, तो false return होगा |
===comparison with typeleft operand को right operand से equal है या नहीं वो check किया जाता है और साथ ही साथ दोनों operands की datatype equal है या नहीं वो देखा जाता है |
<less thanइससे left operand की value right operand की value से कम है या नहीं वो चेक किया जाता है |
>greater thanइससे left operand की value right operand की value से ज्यादा है या नहीं वो चेक किया जाता है |
<=less than equal toleft operand की value right operand की value से कम है या बराबर है वो बताता है |
>=greater than equal to left operand की value right operand की value से ज्यादा है या बराबर है वो बताता है |
!=not equal toleft operand की value right operand की value से equal नहीं हो तो result true आएगी नहीं तो result false मिलेगी |
!==not equal to with datatypeleft operand की value right operand की value से equal भी ना हो और दोनों operands की data type भी एक जैसी ना हो | तभी result true आएगी |

**नॉटपॉइंट !(not) का इस्तेमाल reverse result देने के लिए होता है | !=(not equal) =(equal) का उल्टा और !==(not equal with type) ==(equal with type) का उल्टा काम करता है |

comparison operators example

<!doctype html>
<html>
  <head>
   <title>javascript comparison operator</title>
   <script type="text/javascript">
    var a = 10; var b = 20;  var c = "20";
    var linebreak = "<br />";
	
    document.write("a = " + a + ", ");
    document.write("b =  " + b + ", ");
    document.write("c =  '" + c +"'");

    document.write(linebreak);
	
    document.write("(a > b) result is ");
    document.write(a > b);

    document.write(linebreak);
	
    document.write("(a < b) result is ");
    document.write(a < b);

    document.write(linebreak);
	
    document.write("(a >= b) result is ");
    document.write(a >= b);

    document.write(linebreak);
	
    document.write("(a <= b) result is ");
    document.write(a <= b);

    document.write(linebreak);	
	
    document.write("(a == c) result is ");
    result = (a == c);
    document.write(result);

    document.write(linebreak);
	
    document.write("(a === c) result is ");
    document.write(a === c);

    document.write(linebreak);
	
    document.write("(a != c) result is ");
    document.write(a != b);

    document.write(linebreak);
	
    document.write("(a !== c) result is ");
    document.write(a == b);

    document.write(linebreak);
   </script>
  </head>
  <body>
  </body>
</html>  

result

javascript comparison operators

Logical Operators

assignment operators एक से ज्यादा conditions को चेक करने के लिए इस्तेमाल होती है | if statements या फिर loop में दो या अधिक conditions होतें हैं | तो सारे conditions true हैं या false हैं, उसके हिसाब से loop के अंदर की statement run होती है | और वही conditions check करने के लिए logical operators लिया जाता है |

Logical operators list

ऑपरेटर्सनामविवरण
&&and opeartorअगर सारे conditions true हुए तभी result true होगा नहीं तो ये false return करेगा |
||or operatorअगर सारे conditions में से, एक भी condition true हुआ तभी result true होगा |
!not operatorये condition का उल्टा result देता है | अगर statement true है तो result false आएगा |

and operator condition

condition1condition2result
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

उदाहरण

<script type="text/javascript">
     var a=10;     
     var res = a>8 && a<15; // both conditions are true
     document.write(res); // output -> true
</script>

or operator condition

condition1condition2result
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

उदाहरण

<script type="text/javascript">
     var a=10;
     var res = a>18 || a<15; // 1st condition false, second is true
     document.write(res); // output -> true
 </script>

not operator

conditionresult
truefalse
falsetrue

उदाहरण

<script type="text/javascript">
     var a=10;
     var b=5;	 
     document.write(a!=b); // output -> true
 </script>

Assignment Operators

assignment operators variables या constant को value assign करने के लिए इस्तेमाल किया जाता है |

assignment operators list

operatorsshorthandequivalent expressiondescription
=x=yx=yy की value x को assign करना
+=x+=yx=x+yx और y की value को जोड़ कर पूरी value x को assign करना
-=x-=yx=x-y x से y की value को घटा कर परिणाम x को assign करना
*=x*=yx=x*yx को y से गुणा करके x को assign करना
/=x/=yx=x/yx से y को divide करके परिणाम x को assign करना
%=x%=yx=x%yx से y को divide करके आया हुआ reminder x को assign करना

Conditional Operator

Conditional Operator को ternary operator भी कहा जाता है | ये if else condition का shorthand है | अगर सिर्फ if और else condition लगाना है तो उसे एक ही line में ternary operator के जरिये बताया जा सकता है |

इसमें फर्क ये है की condition और statement को एक ही line में लिख सकते हैं | इसकी वजह से unnecessary अधिक coding की जरुरत नहीं पड़ती | पर इस operators के जरिये दो से अधिक conditions नहीं लिख सकते |

ternary operator syntax
(condition) ? statement1 : statement2;

इस operator में पेहले condition बताई जाती है | अगर condition true हुयी तो statement जिसे ? mark और :(colon) के बिच लिखी गयी है वो run करेगा | अगर condition false हुयी तो statement जिसे :(colon) और ;(semicolon) के बिच में लिखी गयी है वो run करेगा |

conditional operator में पेहली statement true condition के लिए होता है और दूसरा statement false condition के लिए होता है |

उदाहरण

<script type="text/javascript">
  var a=20;
  var res;
  res = (a>10) ? 'true' : res = 'false';
  document.write(res);
</script>

अन्य tutorial के सुझाव