JavaScript Course in Roman Hindi/Urdu - Beginner se Advanced Tak | Lecture 2: JavaScript Operators & Control Flow Full Guide (Yaar, Arithmetic, If-Else, Loops, Switch – Full Deep Dive Se Samajh Aayega!)
Assalam-o-Alaikum yaar! Kya haal hai, dost? Pichli lecture mein JavaScript intro seekh liya – variables, data types se tu ab basics ka boss ban gaya! Ab logic ka time: JavaScript Operators & Control Flow! Yeh JS ka core hai – operators math/logic karte, control flow (if-else, loops, switch) decisions aur repeats. Hum is lecture mein arithmetic/comparison/logical operators, if-else conditional, loops (for/while/do-while), switch cases ko full detail mein bataayenge – har ek ka use kya, kyun zaroori, kahan lagana, aur real examples ke saath, jaise tere saath calculator bana raha hoon. Tension mat le, step-by-step, code copy-paste se try karenge. Yeh seekh le toh programs ko smart banaayega – conditions check, loops data process!
Yaar, operators 1995 se, control flow programming ka base. Ready? Chal shuru!
JavaScript Operators Kya Hain? (Yaar, Overview – Kyun Aur Kab Use Karein)
Dost, Operators values manipulate – arithmetic (+ -), comparison (== >), logical (&& ||). Use: Calculations, conditions. Why: Logic build. Where: If statements, loops. Example: let sum = 5 + 3; if (sum > 7) { console.log('Big'); } – add then check. Without: No math/logic. Types: Unary (one operand), Binary (two).
Fun fact: JS loose == vs strict === – type check matter! Chalo types deep dive!
JavaScript Operators - Har Type Ka Full Explain (Use, Why, Where with Examples)
Yaar, 5 categories, full details: use kya, kyun, kahan, example.
- Arithmetic Operators: Use: Math (+ - * / % ++ --). Why: Calculations. Where: Counters. Example: let a = 10; let b = 3; let sum = a + b; // 13 let mod = a % b; // 1 a++; // 11 Why: Basic ops. % remainder, ++ increment.
let a = 10; let b = 3; let sum = a + b; // 13 let mod = a % b; // 1 a++; // 11 - Assignment Operators: Use: Value assign (= += -= *=). Why: Shorthand. Where: Updates. Example: let x = 5; x += 3; // 8 x *= 2; // 16 Why: x = x + 3 short.
let x = 5; x += 3; // 8 x *= 2; // 16 - Comparison Operators: Use: Check (== === != !== > < >= <=). Why: Conditions. Where: If. Example: 5 == '5' // true (loose) 5 === '5' // false (strict) 10 > 5 // true Why: Loose type coerce, strict safe.
5 == '5' // true (loose) 5 === '5' // false (strict) 10 > 5 // true - Logical Operators: Use: Combine (&& || !). Why: Complex conditions. Where: If. Example: if (age > 18 && isCitizen) { vote(); } !true // false Why: Multiple checks.
if (age > 18 && isCitizen) { vote(); } !true // false - Bitwise Operators: Use: Bits (& | ^ ~ << >>). Why: Low-level. Where: Rare, flags. Example: 5 & 1 // 1 (odd check) Why: Performance hacks.
5 & 1 // 1 (odd check)
Ternary Operator: Use: Shorthand if. Why: Concise. Where: Assignments. Example: let status = age > 18 ? 'Adult' : 'Minor';
let status = age > 18 ? 'Adult' : 'Minor';Yaar Tip: Strict === use avoid bugs. Operators precedence ( * > + ), parentheses use safe.
JavaScript Control Flow - Har Type Ka Full Explain (Use, Why, Where with Examples)
Dost, control flow "decision trees" – if-else conditions, loops repeats, switch cases.
- If-Else: Use: Condition check. Why: Branches. Where: Validation. Example: if (score > 80) { grade = 'A'; } else if (score > 60) { grade = 'B'; } else { grade = 'C'; } Why: Multiple paths.
if (score > 80) { grade = 'A'; } else if (score > 60) { grade = 'B'; } else { grade = 'C'; } - Switch: Use: Multiple cases. Why: Clean if-else chain. Where: Menus. Example: switch (day) { case 1: console.log('Monday'); break; default: console.log('Weekend'); } Break must, else fall through. Why: Readable many cases.
switch (day) { case 1: console.log('Monday'); break; default: console.log('Weekend'); } - For Loop: Use: Known repeats. Why: Iteration. Where: Arrays. Example: for (let i = 0; i < 5; i++) { console.log(i); } 0 to 4 print. Why: Counter control.
for (let i = 0; i < 5; i++) { console.log(i); } - While Loop: Use: Condition true tak run. Why: Unknown repeats. Where: Inputs. Example: let i = 0; while (i < 5) { console.log(i); i++; } Same as for. Why: Check first.
let i = 0; while (i < 5) { console.log(i); i++; } - Do-While: Use: At least once run. Why: Guaranteed execute. Where: Menus. Example: do { console.log(i); i++; } while (i < 5); Run phir check. Why: User input always once.
do { console.log(i); i++; } while (i < 5); - Break/Continue: Use: Loop exit/skip. Why: Control. Where: Conditions. Example: for (let i = 0; i < 10; i++) { if (i === 5) break; console.log(i); } 0-4 print. Continue skip: if (i % 2 === 0) continue; – odd only.
for (let i = 0; i < 10; i++) { if (i === 5) break; console.log(i); }
Yaar Tip: Loops array iterate: for (let item of arr) { console.log(item); } modern.
Apna Pehla Operators & Control Project (Yaar, Hands-On – Step-by-Step with Code)
Dost, ab bana! Simple calculator with if-else loops.
Step 1: Setup
Folder "JS-Logic-Project". Files: index.html. Console open.
Step 2: Code Likh (Full with Why)
index.html:
<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS Logic Demo - Lecture 2</title>
</head>
<body>
<h1>JS Calculator</h1>
<input type="number" id="num1" placeholder="Number 1">
<input type="number" id="num2" placeholder="Number 2">
<button onclick="calculate()">Add</button>
<p id="result"></p>
<script>
function calculate() {
let a = parseInt(document.getElementById('num1').value);
let b = parseInt(document.getElementById('num2').value);
let sum = a + b; /* Arithmetic + */
let diff = a - b; /* - */
let prod = a * b; /* * */
let div = a / b; /* / */
let mod = a % b; /* % */
if (isNaN(a) || isNaN(b)) { /* Logical ||, comparison === */
document.getElementById('result').innerHTML = 'Invalid Numbers';
} else if (sum > 10) {
document.getElementById('result').innerHTML = 'Sum Big: ' + sum;
} else {
document.getElementById('result').innerHTML = 'Sum Small: ' + sum;
}
// Loop example
let loopOutput = '';
for (let i = 0; i < 5; i++) {
loopOutput += 'Loop ' + i + '<br>';
}
console.log(loopOutput);
// Switch
switch (true) {
case sum > 20: console.log('Large'); break;
default: console.log('Small');
}
}
</script>
</body>
</html>
Yaar, Yeh Kaise Kaam Karta? Inputs parse numbers, arithmetic ops sum/diff, if NaN check ||, else if sum >10 big, loop console 0-4, switch true case large/small. Test: Numbers daal click – result show. Mistakes: No parse? String concat. Loop infinite? Condition check.
Step 3: Test aur Tweak (Dost Help)
1. Save, refresh – calculate click? 2. Console – loop output. 3. Tweak: Multiply add, while loop sum print down. Issue: NaN? ParseInt use. Switch no break? Fall through.
Practice Tasks (Yaar, Challenges – Level Up Kar)
- Easy (10 Min): Code copy, *= multiply add, result mein show. (Use: Assignment *=.)
- Medium (15 Min): If age >18 adult else minor alert.
- Advanced (20 Min): For loop array iterate names print, while user input sum until 0.
Dost Challenge: Ek number guess game banao random num, if high/low guess loop. Screenshot!
Common Questions (Yaar, Sab Clear – FAQ Dost Style)
- Q1: == vs === kab ===?
- A: === strict (type+value), == loose (convert). Always === avoid bugs.
- Q2: Loop infinite ka fix?
- A: Condition update kar (i++), break use.
- Q3: Switch string works?
- A: Haan, case "text": code. Why: Menu choices.
- Q4: Ternary multiple?
- A: Nested (a > b ? 'Big' : (a < b ? 'Small' : 'Equal')).
- Q5: Operators precedence?
- A: * / > + -, parentheses () combine safe.
Next Lecture Teaser
Yaar, agla: JavaScript Functions & Scope Full Guide – Arrow Functions, Closures, Hoisting. Logic practice kar, functions easy lagega. Comment bata kaisa tha – saath hain!
Course Outline Hint: - L1: Intro - L2: Operators/Control (Yeh) - L3: Functions - ... L20: Projects.
Doubts ho toh bol, dost. Allah Hafiz! Logic master kar le. 😊

