JavaScript Control Flow: Conditionals u0026 Loops Challenge Quiz

Test your expertise in JavaScript conditional statements, loops, and control flow interrupts with these challenging questions designed to assess nuanced understanding.

  1. Nested Conditional Logic

    Given the code snippet: let x = 10; if (x u003E 5) { if (x u003C 15) { x++; } } else { x = 0; }, what will be the value of x after execution?

    1. 15
    2. 10
    3. 0
    4. 11
    5. 9
  2. Strict vs. Loose Comparison

    In the statement if ('0' == 0), which principle is applied in JavaScript's conditional control flow?

    1. No comparison is made due to syntax error
    2. Strict comparison makes the condition false
    3. Boolean logic is ignored
    4. Type coercion occurs and the condition is true
    5. Type must match exactly
  3. Switch Statement Fallthrough

    Given: let val = 2; switch(val) { case 1: val += 1; case 2: val += 2; break; case 3: val += 3; }, what is the value of val after executing the switch?

    1. 6
    2. 5
    3. 7
    4. 3
    5. 4
  4. Break Statement in Loops

    What will be logged by: let output = ''; for(let i=0; iu003C5; i++) { if(i===3) break; output += i; } console.log(output);

    1. 1234
    2. 3
    3. 012
    4. 0123
    5. 01
  5. Continue in a While Loop

    Which value will NOT be printed by the following? let i = 0; while(i u003C 5) { i++; if(i === 3) continue; console.log(i); }

    1. 4
    2. 5
    3. 3
    4. 2
    5. 1
  6. For...in Loop on Arrays

    Consider let arr = ['a', 'b']; arr.extra = 'c'; Using for (let prop in arr), which values can prop take?

    1. 'a', 'b', 'c'
    2. 'array', 'object', 'extra'
    3. '0', '1', 'extra'
    4. 'arr', 'extra'
    5. '0', '1'
  7. For...of Loop with Sparse Arrays

    Given let arr = [1,,3]; using for (let num of arr), how many iterations will occur and what values will be assigned to num?

    1. 2 iterations: 1 and 3
    2. 2 iterations: 1 and undefined
    3. 3 iterations: 1, undefined, 3
    4. 3 iterations: 1, null, 3
    5. 1 iteration: [1, 3]
  8. Switch Default Case Placement

    What happens if the default case in a switch statement is placed before the first case label?

    1. Only the default runs regardless of other cases
    2. It causes a syntax error
    3. It is valid and executes if no case matches
    4. The switch statement is ignored
    5. The default executes for every case
  9. Short-Circuit Evaluation

    In the expression if (false u0026u0026 someFunction()), what is guaranteed about the execution of someFunction()?

    1. It throws an error
    2. It will always be called
    3. It only runs if false is true
    4. It returns undefined
    5. It will not be called
  10. Loop Scope and Variable Hoisting

    Why does the following code log 5, 5, 5, 5, 5? for(var i=0; iu003C5; i++){ setTimeout(()=u003Econsole.log(i),0); }

    1. Each timeout captures a unique value
    2. The loop doesn’t increment i
    3. let should be used for block scoping
    4. Because 'var' shares function scope and i becomes 5 after the loop
    5. setTimeout delays are synchronous
  11. Do...While vs. While Conditions

    Which statement best describes the difference between do...while and while loops in evaluating loop conditions?

    1. do...while never executes if condition is false
    2. while loops always execute body twice
    3. while guarantees single execution before checking
    4. do...while executes its body at least once regardless of condition
    5. do...while is only for asynchronous code
  12. Combined Conditional Expression

    What is returned by: if (0 || (null u0026u0026 true)) { return 'A'; } else { return 'B'; }

    1. 0
    2. null
    3. undefined
    4. 'B'
    5. 'A'
  13. Switch Statement Case Expression Types

    If a switch statement's case expressions are objects, under what circumstance will any case match?

    1. Matches by JSON stringification
    2. If objects have identical properties
    3. Always matches by value
    4. Only if the same object reference is compared
    5. Never matches anything
  14. For Loop with Multiple Conditions

    What is the result of this code: let res = ''; for(let i=2,j=4; iu003C5u0026u0026ju003E1; i++,j--){ res += i+j; } return res;

    1. '65' (with a space)
    2. '65'
    3. '69'
    4. '710'
    5. '911'
  15. Continue in Nested Loops

    How many times does Hello print in: let count=0; for(let i=0;iu003C3;i++){ for(let j=0;ju003C3;j++){ if(j==1) continue; count++; } } console.log('Hello'.repeat(count));

    1. 8
    2. 9
    3. 6
    4. 3
    5. 12
  16. For...of with Strings

    Given let s = 'abc', what is the output of: let result = ''; for(let c of s){ result += c.toUpperCase(); } return result;

    1. 'abc'
    2. 'A B C'
    3. 'ABC'
    4. 'aBc'
    5. undefined