Introduction to Operators
JavaScript, एक Versatile और Dynamic Programming Language के रूप में Data के Manipulation और विभिन्न Task का Execution करने की सुविधा के लिए Operator की एक Wide Array को Utilize करती है। JavaScript में Operator को विभिन्न Type में Categorized किया जा सकता है, जिनमें से प्रत्येक Language के Syntax में एक Specific Object को Fulfill करता है।
Type of Operators
Arithmetic Operators
Arithmetic Operators, Basic Mathematical Operation करते हैं। इसमें Addition (+), Subtraction (-), Multiplication (*), Division (/), और Modulus Operator (%) शामिल हैं, जो Division का Remainder Return करता है।
Example:
Comparison Operators
Comparison Operators का Use Value को Compare करने और Boolean Result Return करने के लिए किया जाता है। इनमें Equality (==), Strict Equality (===), Inequality (!=), Strict Inequality (!==), Greater Than (>), Less Than (<), Greater Than or Equal To (>=), और Less Than or Equal To (<=) से अधिक या इसके बराबर शामिल हैं।
Example:
Logical Operators
Logical Operators का Use Boolean Values को Combine या Manipulate करने के लिए किया जाता है। Logical AND (&&), Logical OR (||), और Logical NOT (!) Operator का use Complex Decision लेने के किया जाता हैं।
Example:
Assignment Operators
Assignment Operators का Use Variable को Value Assign करने के लिए किया जाता है। Simple Assignment (=) को +=, -=, *=, और /= जैसे Compound Assignment Operators द्वारा Augmented किया जाता है।
Example:
Unary Operators
Unary Operators एक ही Operand पर काम करते हैं। Unary Plus (+) और Unary Minus (-) किसी Number के Sign को बदलते हैं, जबकि Increment (++) और Decrement (–) Operator किसी Variable को 1 से बढ़ाते या घटाते हैं।
Example:
Control Flow Statements
Control Flow Statement, Web Development में Fundamental Structure हैं| जो उस Sequence को निर्धारित करते हैं, जिसमें किसी Program के भीतर Instruction को Execute किया जाता है। ये Statement, Developer को कुछ Condition के आधार पर Execution के Flow को Control करने की अनुमति देते हैं, जिससे Web Application अधिक Dynamic और Responsive बन जाते हैं।
Conditional Statement Developer को Defined Condition के आधार पर Code के कुछ Block को Execute करने की अनुमति देते हैं। सबसे Most Common Conditional Statement हैं –
if Statement
if Statement, Conditional Statement का सबसे Basic Type है। यह एक Condition को Evaluate करता है, और यदि Condition True है, तो Code के एक Block को Execute करता है। अथवा यह Code के Block को Skip कर देता है, और Next Statement पर चला जाता है।
Syntax:
Example:
if-else Statement
if-else Statement का use JavaScript में Decision लेने के लिए किया जाता है। if Condition True है, तो यह आपको Code के एक Block को Execute करने की Permission देता है|और यदि Condition False है, तो दूसरे Block को Execute करने की Permission देता है।
Syntax:
Example:
इस Example में, यदि x का Value 5 से अधिक है, तो Code का पहला Block Execute किया जाएगा; अन्यथा, दूसरा Block Execute किया जाएगा।
Switch Statement
Switch Statement का उपयोग विभिन्न Condition के आधार पर विभिन्न Action करने के लिए किया जाता है। यह if-else statement की Long Chain का एक अधिक Efficient Alternative है।
Syntax:
Looping Statements
Looping Statement का use Code के एक Block को बार-बार Execute करने के लिए किया जाता है, जब तक कि एक Specified Condition True होती है। Common Looping Statement में शामिल हैं-
for Loop
for Loop का उपयोग किसी Array जैसे Element के Sequence पर पुनरावृत्ति करने के लिए किया जाता है। इसमें एक Initialization Statement, एक Condition और एक Increment/Decrement Statement शामिल होता है।
Syntax:
यह Loop Value को 0 से 4 तक Print करेगा। Initialization Let (i=0) Starting Point Set करता है, Condition (i<5) निर्धारित करती है, कि Loop कब रुकना चाहिए| और (i++) प्रत्येक पुनरावृत्ति के बाद (i) का Value बढ़ाता है।
while Loop
एक while Loop Code के एक Block को Repeat करता है, जब Specified Condition True होती है। इसमें केवल एक Conditon होता है| और Loop तब तक जारी रहता है, जब तक वह Condition True है।
Syntax:
Example:
यह Loop Functionally रूप से उपरोक्त Loop Example के बराबर है। यह 0 से 4 तक Value Print करता है ,जबकि Condition (i <5) True है।
do-while Loop
do-while Loop, while Loop के समान है, लेकिन Code के Block Execute होने के बाद Condtion की Check की जाती है। यह सुनिश्चित करता है, कि Block कम से कम एक बार Execute हो।
Syntax:
Example: