Control Statements and Iteration Interview Questions

    Question 1If-Else Condition

    What will be the output of:

    let x = 10; if (x > 15) { console.log("Big"); } else { console.log("Small"); }

    Question 2Switch Statement Default

    What will be the output?

    let fruit = "apple"; switch(fruit) { case "banana": console.log("Yellow"); break; case "orange": console.log("Orange"); break; default: console.log("Unknown"); }

    Question 3For Loop Execution

    How many times will this loop run?

    for (let i = 0; i < 5; i++) { console.log(i); }

    Question 4JS While Loop

    What is the output?

    let i = 0; while (i < 3) { console.log(i); i++; }

    Question 5Do-While Loop Execution

    What is the output?

    let i = 5; do { console.log(i); i++; } while (i < 5);

    Question 6For...of Loop

    What is the output?

    let arr = ["a", "b", "c"]; for (let val of arr) { console.log(val); }

    Question 7for...in Loop

    Which loop is used to iterate over object properties?

    Question 8Break Statement

    What does the break statement do inside a loop?

    Question 9JS Continue Statement

    What is the output?

    for (let i = 0; i < 5; i++) { if (i === 2) continue; console.log(i); }

    Question 10Nested Loop Execution

    How many times will "Hello" be printed?

    for (let i = 0; i < 2; i++) { for (let j = 0; j < 3; j++) { console.log("Hello"); } }