Javascript Control Flow Essentials Quiz Quiz

  1. Evaluating If Statement Execution

    What will be logged to the console after executing: if (5 u003E 2) { console.log('Yes'); } else { console.log('No'); }?

    1. Yes
    2. Null
    3. No
    4. Undefined
    5. Error
  2. Understanding Else If

    Which statement correctly checks if a variable 'score' is greater than 90, and prints 'Excellent' if true, 'Good' if exactly 90, otherwise 'Try again'?

    1. if (score =u003E 90) { console.log('Excellent'); } else { console.log('Good'); }
    2. if (score = 90) { console.log('Excellent'); } else { console.log('Try again'); }
    3. if (score u003E 90) { console.log('Excellent'); } else if (score === 90) { console.log('Good'); } else { console.log('Try again'); }
    4. if score u003E 90 then console.log('Excellent'); else console.log('Try again');
    5. if (score u003E= 90) { console.log('Excellent'); } else { console.log('Good'); }
  3. Detecting Switch Syntax

    Which of the following is a correct way to start a switch statement in JavaScript?

    1. switch(variable) {
    2. switch { variable }
    3. case (variable) {
    4. switch: (variable) {
    5. switch variable {
  4. Case Matching in Switch

    When using a switch statement, what happens if none of the case values match the expression?

    1. The code inside the default block runs, if present.
    2. The first case block always executes.
    3. Switch stops all execution in the program.
    4. An error is thrown.
    5. The switch block is skipped entirely.
  5. For Loop Basics

    Which for loop will correctly print numbers 0 through 4 to the console?

    1. for (let i = 1; i u003C= 5; i++) { console.log(i); }
    2. for (var i = 5; i u003E= 0; i++) { console.log(i); }
    3. for let i = 0; i u003C 5; i++ { console.log(i); }
    4. for (let i = 0; i u003C 5; i++) { console.log(i); }
    5. for (i = 0; i u003C 5; i--) { console.log(i); }
  6. While Loop Execution

    Given: let x = 3; while (x u003E 0) { x--; } What will be the value of x after the loop finishes?

    1. undefined
    2. 1
    3. 3
    4. 4
    5. 0
  7. Do...While Difference

    How does a do...while loop differ from a while loop in JavaScript?

    1. A do...while loop only executes if the condition is true initially.
    2. A do...while loop will never execute if the condition is false.
    3. A do...while loop cannot use break.
    4. A do...while loop can only run for arrays.
    5. A do...while loop always executes its body at least once.
  8. Using Continue in Loops

    If you use 'continue' inside a for loop, what happens to the current iteration?

    1. Nothing changes; the loop runs as usual.
    2. An error occurs.
    3. The current iteration stops, and the loop proceeds to the next iteration.
    4. All iterations are skipped.
    5. The loop breaks completely.
  9. Purpose of Break Statement

    What is the main purpose of the 'break' statement inside loops?

    1. To pause the loop and resume later.
    2. To exit the loop immediately.
    3. To reverse the loop direction.
    4. To skip to the end of the current iteration.
    5. To restart the loop.
  10. For...of Loop Use Case

    Which statement best describes the use of a for...of loop in JavaScript?

    1. It iterates over the properties of an object.
    2. It loops indefinitely.
    3. It only works with string types.
    4. It iterates over numbers from 0 to 10 automatically.
    5. It iterates over the values of an iterable object like an array.
  11. For...in Loop Application

    What does a for...in loop do when used with an object?

    1. It loops through each element in an array.
    2. It creates new properties for the object.
    3. It iterates over the object's enumerable property names.
    4. It iterates over the object's values.
    5. It sorts the object's keys alphabetically.
  12. Else Without If

    Is it valid to use an else block in JavaScript without a preceding if statement?

    1. Else can only follow loops.
    2. No, an else must follow an if statement.
    3. Else can only follow switch statements.
    4. Else is not used in JavaScript.
    5. Yes, else statements can exist independently.
  13. Default Keyword in Switch

    In a switch statement, what is the role of the default keyword?

    1. To specify the first case to check.
    2. To initialize the switch values.
    3. To terminate the switch immediately.
    4. To handle any case not matched by a case label.
    5. To define a variable inside switch.
  14. Increment in For Loops

    In the for loop for (let i = 0; i u003C 5; i++), what does i++ do?

    1. It decreases i by 1 after each iteration.
    2. It multiplies i by 2 in each iteration.
    3. It stops the loop.
    4. It increases the value of i by 1 after each iteration.
    5. It checks if i is even.
  15. Breaking Out of Nested Loops

    Given two nested for loops, what happens when a break statement is called inside the inner loop?

    1. It exits both loops.
    2. It throws an error.
    3. It exits only the inner loop.
    4. It pauses all loops.
    5. It restarts the inner loop.
  16. Checking Truthy and Falsy Values

    Which value will cause an if statement if (x) to consider x as false?

    1. {}
    2. []
    3. 0
    4. 'Hello'
    5. 10