Course Progress 71%

JavaScript Arithmetic Operators

JavaScript में Arithmetic Operators का उपयोग numbers पर mathematical calculations करने के लिए किया जाता है। इन operators की मदद से हम addition, subtraction, multiplication, division जैसे basic calculations कर सकते हैं।

Beginner के लिए Arithmetic Operators समझना बहुत जरूरी है, क्योंकि calculations almost हर JavaScript program का core हिस्सा होती हैं।

Arithmetic Operators की List

JavaScript में commonly used arithmetic operators ये हैं:

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus
  • ++ Increment
  • -- Decrement

अब हम हर operator को simple language और practical examples के साथ समझते हैं।

Addition Operator (+)

Addition operator दो numbers को जोड़ने के लिए use होता है।

Example: Addition Operator

<script>
let a = 10;
let b = 20;
let sum = a + b;
</script>

यह code a और b की values को add करता है।

10 + 20 का result 30 होता है, जो sum variable में store हो जाता है।

इस code का final result memory में sum = 30 होगा।

Addition operator का use तब किया जाता है जब हमें numbers को जोड़कर नया result निकालना हो।

Subtraction Operator (-)

Subtraction operator एक number में से दूसरे number को घटाने के लिए use होता है।

Example: Subtraction Operator

<script>
let x = 50;
let y = 15;
let result = x - y;
</script>

यह code 50 - 15 calculate करता है।

Result 35 होगा और result variable में store होगा।

Subtraction operator का use difference निकालने के लिए किया जाता है।

Multiplication Operator (*)

Multiplication operator numbers को multiply करने के लिए use होता है।

Example: Multiplication Operator

<script>
let p = 6;
let q = 4;
let total = p * q;
</script>

यह code 6 * 4 calculate करता है।

Result 24 होगा और total variable में store होगा।

Multiplication operator का use तब किया जाता है जब repeated addition की जरूरत हो।

Division Operator (/)

Division operator एक number को दूसरे number से divide करता है।

Example: Division Operator

<script>
let num1 = 40;
let num2 = 8;
let output = num1 / num2;
</script>

यह code 40 / 8 calculate करता है।

Result 5 होगा और output variable में store होगा।

Division operator का use तब किया जाता है जब equal parts में value divide करनी हो।

Modulus Operator (%)

Modulus operator division के बाद बचा हुआ remainder return करता है।

Example: Modulus Operator

<script>
let a = 17;
let b = 5;
let remainder = a % b;
</script>

यह code 17 को 5 से divide करता है।

5 * 3 = 15 होता है और remainder 2 बचता है।

Final result remainder = 2 होगा।

Modulus operator का use even-odd check करने और remainder निकालने के लिए किया जाता है।

Increment Operator (++)

Increment operator variable की value को 1 से increase करता है।

Example: Increment Operator

<script>
let count = 7;
count++;
</script>

पहले count की value 7 है।

count++ के बाद value 8 हो जाती है।

Increment operator loops और counters में बहुत useful होता है।

Decrement Operator (–)

Decrement operator variable की value को 1 से decrease करता है।

Example: Decrement Operator

<script>
let number = 10;
number--;
</script>

पहले number की value 10 है।

number-- के बाद value 9 हो जाती है।

Decrement operator countdown और reverse loops में use होता है।

Prefix और Postfix Increment

Increment और decrement operator prefix और postfix दोनों form में use किए जा सकते हैं।

Postfix Example

<script>
let x = 5;
let y = x++;
</script>

यहां पहले y को x की current value 5 assign होती है।

उसके बाद x की value increase होकर 6 हो जाती है।

Final values होंगी:
x = 6
y = 5

Prefix Example

<script>
let a = 5;
let b = ++a;
</script>

यहां पहले a की value increase होकर 6 हो जाती है।

फिर b को value 6 assign होती है।

Final values होंगी:
a = 6
b = 6

Prefix और postfix का difference समझना beginners के लिए बहुत important है।

Arithmetic Operators और Strings

+ operator strings के साथ भी काम करता है।

Example: Number + String

<script>
let result = 10 + "5";
</script>

यह code number को string में convert कर देता है।

Result "105" होगा, जो string datatype का होगा।

यह behavior JavaScript की automatic type conversion की वजह से होता है।

Arithmetic Operators का Practical Use

Arithmetic operators का use:

  • Calculations करने में
  • Totals और averages निकालने में
  • Counters और loops बनाने में
  • Mathematical logic develop करने में

Arithmetic operators JavaScript programming की foundation हैं और इन्हें अच्छे से समझना हर beginner के लिए जरूरी है।