Advertisement

Learn Control Structures in JavaScript in Hindi ??? Easy Guide for Beginners

JavaScript ????????? Control Structures ??????????????????????????? ?????? ????????????????????? ???????????? ?????? ???????????? ??????????????? ???????????? ?????? ??????????????? Conditionals (if, else if, else, switch, ternary operator) ?????? Loops (for, while, do-while) ?????? ????????? ???????????? ????????? ?????????????????? ????????? ????????? ??????, break, continue, nested loops, ?????????????????????????????? ??????????????????????????? (??????????????????????????????????????? ???????????? ?????? ?????????????????? ???????????? ?????????), 5 MCQ ??????????????????, ?????? ???????????? ??????????????????????????? (???????????? ?????????????????? ?????????) ???????????? JavaScript ????????????????????? ?????? ??????????????????????????? ?????? ???????????? ??????????????? ????????? ??????, ???????????????????????? ?????????????????? (???????????? if, for) English ????????? ?????????, ?????? ????????? ???????????? ????????? English ????????? ?????????

What is Control Structures in JavaScript with example in Hindi (JavaScript ????????? ????????????????????? ??????????????????????????? ???????????? ???????????? ?????????, ?????????????????? ????????????)

Control Structures ??????????????????????????? ?????? ?????? ??????????????? ????????? ?????? ?????? ???????????? ???????????? ????????? Conditionals ?????????????????? ???????????? ?????????, ???????????? ??????????????? ?????? ???????????? ????????? ??????????????? Loops ????????? ?????? ?????????-????????? ??????????????? ?????????, ???????????? ???????????? ??????????????? ?????????????????? ??????????????? JavaScript ????????? ???????????????????????? Truthy (???????????? 1, "hello") ?????? Falsy (0, "", null) ????????? ??????????????? ???????????? ????????? ???????????????????????? ?????? ???????????? ?????? ???????????? ???????????? ??????????????? ???????????????????????????: ?????????????????? ?????????, let ???????????? ??????????????? ???????????? ?????????: ??????????????? ???????????????, ???????????? ????????????????????????????????? ????????????????????????: ????????? ???????????????, ????????????????????? ??????????????????

let isLoggedIn = true;

if (isLoggedIn) {

console.log("Welcome to the app!");

} else {

console.log("Please log in.");

}

Types of conditional statements in JavaScript with examples in Hindi

Conditionals ??????????????????????????? ?????? ???????????????????????? ?????? ???????????? ?????? ?????????????????? ???????????? ????????? ????????? ???????????? ???????????? ?????? ????????? ???????????? ????????? ?????? ?????????????????? Truthy ?????? ?????? Falsy, ?????? ????????? ??????????????? ?????? ????????? ???????????? ?????????

Advertisement

if: Checking a condition

if ?????? ?????????????????? ????????? ???????????? ????????? ????????? ?????????????????? Truthy, ?????? ????????? ??????????????? ???????????? ??????, ???????????? ?????????????????? let ??????????????? ?????? ??????????????? ???????????? ????????? ????????? ?????????????????? ?????? ???????????? ?????? ???????????? ???????????? ??????????????? ???????????????????????????: ?????????????????? ????????????????????????, === ???????????? ??????????????? ???????????? ?????????: ??????????????? ??????????????????????????? ????????????????????????: ????????? ?????????????????? ?????? ??????????????????????????? ??????????????????????????????

let age = 18;

if (age >= 18) {

console.log("You can vote!");

}

else if: Checking multiple Conditions

else if ?????? ???????????????????????? ????????? ???????????? ????????? ???????????? Truthy ?????????????????? ?????? ??????????????? ???????????? ????????? ?????? ?????? ????????? ?????? ????????? ???????????? ????????? ????????? ??????????????? ?????? ??????????????? ??????????????? ???????????????????????????: ?????? else if, ??????????????????????????? ?????????????????? ??????????????? ???????????? ?????????: ???????????????????????? ????????????????????? ????????????????????????: ?????????????????? ???????????????????????????

let score = 85;

if (score >= 90) {

console.log("Grade: A");

} else if (score >= 80) {

console.log("Grade: B");

} else if (score >= 70) {

console.log("Grade: C");

} else if (score >= 60) {

console.log("Grade: D");

} else {

console.log("Fail");

}

else: Default Condition

else ?????? ???????????? ?????? ?????? ????????? ?????????????????? Truthy ??????????????? ????????????????????? ?????????????????? ???????????? ????????? ????????? ?????????????????? ????????????, ?????????????????? ??????????????? ???????????????????????????: ????????????????????? ?????????????????? ???????????? ?????????: ????????? ??????????????????????????? ????????????????????????: ???????????????????????? else???

Advertisement

let temperature = 15;

if (temperature > 30) {

console.log("It's hot!");

} else {

console.log("It's cool!");

}

switch: Checking multiple values

switch ?????? ?????????????????? ?????? ?????? ????????? ?????? === ?????? ????????? ????????? ???????????? ????????? ?????????????????? ????????? ???????????? ????????? break ??? ???????????? ?????? ?????????-??????????????? default ????????????????????? ????????? ??????????????? ???????????? ????????? ??????????????? ???????????????????????????: break, default ???????????? ??????????????? ???????????? ?????????: ?????? ?????? ???????????? ????????????????????????: ?????????-????????????, ????????? ???????????????

switch (day) {

case 1: console.log("Monday"); break;

case 2: console.log("Tuesday"); break;

case 3: console.log("Wednesday"); break;

case 4: console.log("Thursday"); break;

case 5: console.log("Friday"); break;

case 6: console.log("Saturday"); break;

case 7: console.log("Sunday"); break;

default: console.log("Invalid day");

}

Ternary Operator: Short Conditional

Ternary Operator (condition ? expr1 : expr2) ???????????????-???????????? ????????????????????? ????????? Truthy ?????? ????????????, Falsy ?????? ??????????????? ????????????????????????????????? ???????????????, ??????????????? ???????????????????????? ??????????????????????????? ??????????????? ???????????????????????????: ?????????????????? ??????????????? ???????????? ?????????: ????????????????????? ?????????????????????????????? ????????????????????????: ????????????????????? ?????????????????????

let age = 20;

let isAdult = age >= 18 ? "Yes" : "No";

console.log(isAdult); // Yes

Types of Loops in JavaScript with examples in Hindi

Loops ????????? ?????? ??????????????? ???????????? ???????????? for ????????????????????? ????????????????????????, while ????????????????????????, do-while ?????? ?????? ?????? ?????? ????????? ????????? ???????????????????????? ?????? ????????????????????? ?????????????????? ??????????????? ???????????????????????????: let, ?????????????????? ?????????????????? ???????????? ?????????: ???????????? ????????????????????????????????? ????????????????????????: ????????? ????????????????????????????????????

for: Fixed Iterations

for ????????? ?????? counter-controlled iteration construct ?????? ?????? ????????? ?????? ?????? ??????????????????????????? ?????????????????? ????????? ????????? ??????????????? ?????? ????????? ?????????????????? ???????????? ????????? ?????? initialization ??? condition check ??? increment/decrement ?????? ???????????????????????? ?????? ?????????????????? ???????????? ????????? ???????????????????????? ????????? predictable iteration pattern ?????? ???????????? highly optimized ???????????? ?????????

for (let i = 1; i <= 5; i++) {

console.log(i); // 1, 2, 3, 4, 5

}

while: Dynamic Iterations

while ????????? ?????? entry-controlled iteration ?????? ?????? ?????? ?????? ???????????? ?????? ?????? ?????? ?????? ?????? boolean expression truthy ???????????? ????????? ?????? ?????? ???????????????????????????????????? ?????? ????????? ????????????????????? ?????? ???????????? iteration count uncertain ?????? dynamic ???????????? ????????? ?????? ???????????? runtime-driven control ???????????? ?????????

let i = 1;

while (i <= 5) {

console.log(i);

i++;

}

do-while: At least one run

do-while ?????? post-tested loop construct ?????? ?????? body ?????? ?????? ?????? ?????? ?????? ????????? execute ???????????? ??????, ????????? ?????? condition false ????????? ?????? mandatory first-run logic ???????????? scenarios ????????? ?????????????????? ???????????? ???????????? ?????????

let i = 1;

do {

console.log(i);

i++;

} while (i <= 5);

Break: Stop Loop

break statement ?????? control transfer keyword ?????? ?????? ????????? ?????? normal flow ?????? ??????????????? ?????????????????? ?????? ???????????? ????????? ?????? nested loops ?????? conditional exits ????????? execution efficiency ?????????????????? ????????? ????????? ???????????? ?????????

for (let i = 1; i <= 5; i++) {

if (i === 3) break;

console.log(i); // 1, 2

}

Continue: Skipping an Iteration

continue statement ????????? ?????? current iteration ?????? skip ?????? ???????????? iteration ?????? jump ???????????? ????????? ?????? conditional skipping ????????? ?????????????????? ???????????? ?????? ???????????? ????????? values ?????? cases ?????? process ???????????? ???????????? ?????????

for (let i = 1; i <= 5; i++) {

  if (i === 3) continue;

  console.log(i); // 1, 2, 4, 5

}

Nested Loops: Multi-Level Interaction

Nested loop ???????????? loop within a loop, complex data structures ?????? multi-dimensional arrays ?????? ????????? ???????????? ?????? ????????? ?????????????????? ???????????? ???????????? ?????? inner loop outer loop ?????? ?????? iteration ?????? ????????? execute ???????????? ??????, ??????????????? time complexity ??????????????? ?????? - ??????????????? O(n??) ?????? ???????????????

for (let i = 1; i <= 3; i++) {

  for (let j = 1; j <= 2; j++) {

    console.log(`i=${i}, j=${j}`);

  }

}

Exercise: Multiplication Table & Primary Number Check

Task 1: 1-10 ?????? ???????????? ???????????? ??????????????????????????????????????? ???????????? ?????????????????? ???????????????

Task 2: ???????????? ????????? ???????????? ?????? ?????????????????? ?????? ?????? ???????????????

??????????????? ???????????????????????????: ??????????????????????????? ???????????? ?????????: ????????? ???????????????

// Multiplication Table

let num = parseInt(prompt("Enter number (1-10):"));

if (!isNaN(num) && num >= 1 && num <= 10) {

for (let i = 1; i <= 10; i++) {

console.log(`${num} x ${i} = ${num * i}`);

}

} else {

console.log("Invalid input (1-10 only)");

}

// Prime Check

let number = parseInt(prompt("Enter number to check prime:"));

if (isNaN(number)) {

console.log("Invalid input");

} else {

let isPrime = true;

if (number <= 1) {

isPrime = false;

} else {

for (let i = 2; i <= Math.sqrt(number); i++) {

if (number % i === 0) {

isPrime = false;

break;

}

}

}

console.log(`${number} ${isPrime ? "is prime" : "is not prime"}`);

}

Quiz: Loop & Conditional Logic

What is the output of if (x > 10) { console.log("Big"); } else { console.log("Small"); } when x = 5?

  • A) Big
  • B) Small
  • C) Error
  • D) Undefined

Answer: B) Small

2. What is the output of for (let i = 0; i < 3; i++) { console.log(i); }?

  • A) 1, 2, 3
  • B) 0, 1, 2
  • C) 0, 1, 2, 3
  • D) Infinite loop

Answer: B) 0, 1, 2

3. What is the output of switch (color) { case "red": console.log("Stop"); break; default: console.log("Go"); } when color = "green"?

  • A) Stop
  • B) Go
  • C) Error
  • D) Nothing

Answer: B) Go

4. What is the output of let i = 0; while (i < 3) { console.log(i); i++; }?

  • A) 0, 1, 2
  • B) 1, 2, 3
  • C) Infinite
  • D) 0, 1

Answer: A) 0, 1, 2

5. What is the output of for (let i = 1; i <= 5; i++) { if (i === 3) continue; console.log(i); }?

  • A) 1, 2, 3, 4, 5
  • B) 1, 2, 4, 5
  • C) 3
  • D) 1, 2 

Answer: B) 1, 2, 4, 5

Mini Project: ???????????? ?????????????????? ?????????

Task: 1-100 ?????? ????????? ??????????????? ???????????? ??????????????? ????????????, ??????????????? ????????? ???????????? ????????????????????? (Too high/low) ?????? ????????? ?????????????????? do-while ??????????????? ??????????????? ???????????????????????????: ??????????????????????????? ???????????? ?????????: ??????????????????

let randomNumber = Math.floor(Math.random() * 100) + 1;

let guessCount = 0;

let userGuess;


do {

  userGuess = parseInt(prompt("Guess a number between 1 and 100:"));

  guessCount++;

  if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) {

    console.log("Please enter a valid number between 1 and 100");

  } else if (userGuess > randomNumber) {

    console.log("Too high! Try again.");

  } else if (userGuess < randomNumber) {

    console.log("Too low! Try again.");

  } else {

    console.log(`Congratulations! You guessed the number ${randomNumber} in ${guessCount} attempts!`);

  }

} while (userGuess !== randomNumber);

Conclusion

Control Structures JavaScript ????????? ??????????????????????????? ?????? ????????????????????? ??????????????? ???????????? Conditionals ?????? Loops ?????? ?????????????????? ?????? ??????????????? ????????????????????? ???????????? ?????? ???????????? ???????????? ??????????????????????????? ???????????? ?????? ???????????? ????????????????????? ????????? ???????????????????????? ??????????????????

Also Read: 


Table of Contents

Close

Share to other apps

Report Content

Why are you reporting this content?

Your selection helps us review the content and take appropriate action.

Hate & Discrimination
Content that spreads hate or unfair treatment against a person or group because of who they are.
Abuse & Harassment
Content that insults, threatens, bullies, or makes someone uncomfortable.
Violence & Threats
Content that talks about hurting people, animals, or property, or supports violence.
Child Safety
Any content that harms, exploits, or puts children at risk.
Privacy Violation
Sharing someone’s personal information or photos without permission.
Illegal & Regulated Activities
Content that promotes or helps with illegal activities like drugs, weapons, or trafficking.
Spam & Misleading Content
Fake, misleading, or repeated content meant to trick users.
Suicide or Self-Harm
Content that encourages or explains self-harm or suicide.
Sensitive or Disturbing Content
Shocking or graphic content that may upset users.
Impersonation
Pretending to be another person or organization.
Extremism & Hate Groups
Content that supports violent groups or hateful ideas.
Civic Integrity
Content that spreads false information about elections or public processes.