Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

JavaScript Control Structures Practice Quiz

Master coding skills with interactive practice exercises

Difficulty: Moderate
Grade: Grade 10
Study OutcomesCheat Sheet
Colorful paper art promoting a JavaScript trivia quiz for high school students.

Which of the following is the correct syntax for an if statement in JavaScript?
if condition { // code }
if (condition): // code
if { condition } code
if (condition) { // code }
The correct syntax for an if statement places the condition in parentheses and the code block in curly braces. This structure clearly separates the condition from the executable code.
Which operator is used to compare both value and type in JavaScript?
===
=
==
!==
The strict equality operator '===' checks for both value and type equality. The other operators either perform type coercion or serve different purposes such as assignment.
Which keyword is used to exit a case in a switch statement?
end
exit
break
stop
The 'break' keyword is used to exit a case within a switch statement to prevent fall-through to subsequent cases. Without it, multiple cases may execute unintentionally.
Which loop guarantees that the code block executes at least once in JavaScript?
while
do...while
none
for
The do...while loop executes its code block at least once before checking the condition. This ensures that the block runs regardless of whether the condition is initially true or false.
What does the 'continue' statement do in a loop in JavaScript?
It exits the loop entirely
It skips to the next iteration
It restarts the loop
It stops the program
The 'continue' statement causes the loop to immediately skip the rest of the current iteration and proceed to the next one. This is different from 'break', which exits the loop completely.
Given a variable x with value 5, which if statement correctly checks if x is greater than 3 and less than 10?
if (x > 3 and x < 10)
if (x > 3, x < 10)
if (x > 3 || x < 10)
if (x > 3 && x < 10)
The correct syntax uses the logical AND operator '&&' to ensure both conditions are satisfied. The other options either use the wrong operator or incorrect syntax.
In a for loop, which part is used to update the loop variable after each iteration?
The condition expression
The initialization expression
The increment expression
The loop body
The increment expression is executed after each iteration to update the loop variable. The initialization sets the starting value and the condition determines if the loop continues.
What is the output of the following code snippet? let count = 0; while (count < 3) { console.log(count); count++; }
0 1 2
1 2 3
0 1 2 3
1 2
The loop starts at 0, prints 0, then 1, and finally 2 before the condition fails when count becomes 3. This demonstrates a typical while loop execution.
Which of the following statements about the ternary operator in JavaScript is correct?
It requires curly braces around its expressions
It is a shorthand for an if-else statement
It always returns a boolean value
It can have multiple conditions without chaining
The ternary operator provides a concise alternative to a full if-else statement by returning one of two values based on a condition. It does not return a boolean by default and does not require curly braces.
What will be logged if the following code is executed? for (let i = 0; i < 3; i++) { if (i === 1) continue; console.log(i); }
1, 2
0, 1, 2
0, 2
0, 1
When i equals 1, the continue statement skips the console.log call, so only 0 and 2 are printed. This question tests understanding of how continue affects loop execution.
In a switch statement, what happens when no matching case is found and a default block is provided?
The last case is executed
An error is thrown
The switch statement exits without executing any code
The default block is executed
When no case matches in a switch statement, the default block is executed if present. This acts as a fallback to handle any unmatched cases.
Which logical operator in JavaScript returns true if at least one operand is truthy?
&& (AND)
|| (OR)
?? (Nullish Coalescing)
! (NOT)
The OR operator (||) evaluates to true when at least one of its operands is true. In contrast, the AND operator requires both operands to be true.
In JavaScript, what is the purpose of the break statement inside a loop?
It skips the current iteration
It terminates the loop immediately
It pauses the loop temporarily
It resets the loop variable
The break statement immediately exits the loop, preventing further iterations. This is useful when a desired condition has been met and further processing is unnecessary.
Which of the following is a valid use of the do...while loop?
do { console.log('Hello'); } while;
do { console.log('Hello'); } while(false);
do { console.log('Hello'); } while(console.log('Hi'));
do { console.log('Hello'); }
Option A demonstrates the correct syntax for a do...while loop, where the code block is executed once before the condition is evaluated. The other options contain syntax errors.
How can you check if a variable, myVar, is defined and not null in JavaScript?
if (myVar !== null)
if (myVar != null)
if (myVar == undefined)
if (typeof myVar === 'undefined')
Using 'if (myVar != null)' checks for both null and undefined due to type coercion, making it a concise method to verify that a variable is defined. The other options only handle one possible state.
Consider the following code snippet: let x = 0; while (x < 10) { if (x % 2 === 0) { x += 3; } else { x++; } console.log(x); } Which of the following best describes the iteration behavior in this loop?
The loop only executes the increment path
The loop always increments x by 1, ignoring the condition
The loop has an infinite loop because x is never updated
The loop alternates between adding 3 and incrementing by 1 based on the even/odd value of x
The code checks if x is even; if so, it adds 3, otherwise it increments by 1. This conditional updating of x leads to a non-uniform progression through the loop.
What is the result of the following logical expression: !((false || true) && !(false && true))?
true
error
false
 
By evaluating step-by-step: false || true results in true, false && true results in false so its negation is true, then true && true is true, and finally the outer negation gives false. Hence, the expression evaluates to false.
In a switch-case structure, what problem might arise from not using break statements?
Syntax errors
Fall-through error, causing unintended code execution
The switch statement will be ignored
No output will be produced
Without break statements, the execution falls through to subsequent cases even when a match is found, leading to unintentional execution of code blocks. This is a common source of bugs in switch-case structures.
In a nested loop scenario, which statement can be used to exit only the inner loop without affecting the outer loop?
continue
return
break
exit
Using break within the inner loop will terminate that loop while leaving the outer loop unaffected. This is useful for controlling nested loop execution.
How does short-circuit evaluation in logical operators enhance performance in control flow statements in JavaScript?
It compiles the code faster
It evaluates all conditions regardless
It replaces conditional statements
It stops evaluating the remaining expressions once the outcome is determined
Short-circuit evaluation halts further evaluation of conditions once the outcome is determined, reducing unnecessary computations. This efficiency can be beneficial in complex conditional statements.
0
{"name":"Which of the following is the correct syntax for an if statement in JavaScript?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Which of the following is the correct syntax for an if statement in JavaScript?, Which operator is used to compare both value and type in JavaScript?, Which keyword is used to exit a case in a switch statement?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Study Outcomes

  1. Understand how to implement conditional statements in JavaScript.
  2. Apply looping constructs to manage iterative processes.
  3. Analyze code to identify and resolve logical flow issues.
  4. Evaluate and debug control structure implementations.
  5. Interpret coding puzzles to enhance logical reasoning skills.

4.12.1 JavaScript Control Structures Cheat Sheet

  1. Master the if Statement - The if statement is your basic decision-maker. It checks a condition and runs the code inside its block only when that condition is true, giving you control over what happens next. Practice simple age or score checks to see how it branches your program flow! Read more on GeeksforGeeks
  2. Utilize if...else for Decision Making - The if...else structure lets you choose between two paths: one when the condition is true, and another when it's false. It's perfect for scenarios like pass/fail messages or feature toggles. Embrace both sides of the coin to keep your logic clear and concise! Read more on GeeksforGeeks
  3. Implement if...else if...else for Multiple Conditions - When two options aren't enough, chain together else if blocks to handle extra cases. This lets you cover several scenarios in a neat, ordered sequence - ideal for grading systems or temperature ranges. Just watch out for overlapping conditions to avoid surprises! Read more on GeeksforGeeks
  4. Understand the switch Statement - The switch statement compares a single expression against many cases, making it cleaner than a long chain of if...else if. It's like a multiple-choice quiz: pick the matching case and run its block. Don't forget break after each case to prevent fall‑through! Read more on GeeksforGeeks
  5. Practice the for Loop - The for loop is your go-to when you know in advance how many times you want to run a block of code. It bundles initialization, condition-checking, and iteration in one line - perfect for counting or iterating over arrays. Master it to automate repetitive tasks effortlessly! Read more on GeeksforGeeks
  6. Explore the while Loop - The while loop repeats its block as long as the condition stays true, giving you flexibility when you don't know the iteration count up front. Just be mindful to update your condition inside the loop to avoid infinite loops that crash your code! Read more on GeeksforGeeks
  7. Learn the do...while Loop - The do...while loop guarantees at least one run of its block before checking the condition, making it ideal for user prompts or menu displays. Use it when you want an initial action followed by a repeat check - no extra flags needed! Read more on GeeksforGeeks
  8. Use the break Statement - break is your emergency stop inside loops or switch statements. It immediately exits the nearest loop or switch block, which is super handy when you've found what you're looking for or need to bail out early. Use it sparingly for cleaner logic! Read more on GeeksforGeeks
  9. Apply the continue Statement - continue skips the rest of the current loop iteration and jumps straight to the next one. It's like saying "not this time" when you hit a certain condition, letting you filter out unwanted cases without breaking the loop entirely. Perfect for data validation or selective processing! Read more on GeeksforGeeks
  10. Understand the return Statement - Inside a function, return stops execution immediately and optionally sends a value back to the caller. It's how you package up results and exit gracefully - think of it as the function's way of handing back its final answer. Use it to keep your functions focused and efficient! Read more on GeeksforGeeks
Powered by: Quiz Maker