javascript-control-structures-quiz

Mastering JavaScript control structures is essential for creating efficient and effective code. This quiz will test your understanding of loops, conditionals, and other control structures that are fundamental to JavaScript programming. Get ready to enhance your coding skills and prove your expertise!
We recommend that you do not leave the page that you are taking this quiz in. Stay honest 🙂
JavaScript Control Structures Quiz
0% Complete
1 of 16
1. Which of the following is the correct syntax for a ‘for’ loop in JavaScript?
Choose the correct syntax for a ‘for’ loop.

JavaScript Control Structures Quiz Questions Overview

1. Which of the following is the correct syntax for a ‘for’ loop in JavaScript?

for (i = 0; i < 5; i++)
for i = 0 to 5
for (i <= 5; i++)
for (i = 0; i < 5)

2. What is the purpose of the ‘break’ statement in JavaScript?

To exit a loop or switch statement
To pause the execution of a loop
To skip the current iteration of a loop
To define a new scope

3. Which of the following is NOT a valid JavaScript loop?

for
while
do-while
repeat-until

4. What will the following code output? ‘if (true) { console.log(‘Hello’); } else { console.log(‘Goodbye’); }’

Hello
Goodbye
Error
Nothing

5. What is the purpose of the ‘continue’ statement in JavaScript?

To exit a loop
To pause the execution of a loop
To skip the current iteration of a loop
To define a new scope

6. Which of the following is the correct syntax for an ‘if’ statement in JavaScript?

if i = 5 then
if (i == 5)
if i == 5
if (i = 5)

7. What will the following code output? ‘for (var i = 0; i < 3; i++) { console.log(i); }'

0 1 2
1 2 3
0 1 2 3
undefined

8. Which of the following is the correct syntax for a ‘switch’ statement in JavaScript?

switch (expression) { case value: // code break; }
switch expression { case value: // code break; }
switch (expression) { case value: // code }
switch expression { case value: // code }

9. What will the following code output? ‘var x = 10; while (x > 5) { x–; } console.log(x);’

10
5
4
undefined

10. Which of the following is the correct syntax for a ‘do-while’ loop in JavaScript?

do { // code } while (condition);
do (condition) { // code };
do { // code } while condition;
do { // code } until (condition);

11. What is the output of the following code? ‘if (false) { console.log(‘True’); } else { console.log(‘False’); }’

True
False
Error
Nothing

12. What will the following code output? ‘for (var i = 0; i < 2; i++) { for (var j = 0; j < 2; j++) { console.log(i + ',' + j); } }'

0,0 0,1 1,0 1,1
0,0 1,0 0,1 1,1
0,1 1,0 0,0 1,1
1,1 0,0 0,1 1,0

13. Which of the following statements is used to handle exceptions in JavaScript?

try-catch
try-except
try-finally
catch-finally

14. What will the following code output? ‘var a = 5; if (a > 3) { a = a * 2; } console.log(a);’

5
10
15
Error

15. Which of the following is the correct syntax for a ‘while’ loop in JavaScript?

while (condition) { // code }
while condition { // code }
while (condition) // code
while { condition } // code

16. What will the following code output? ‘var x = 0; do { x++; } while (x < 3); console.log(x);'

0
1
2
3
We recommend that you do not leave the page that you are taking this quiz in. Stay honest 🙂
We have chosen the next challenge for you. Take the next test:

Can Your Friends Do Better Than You in This Quiz?

Share this quiz with your friends and compare results.

Was this page helpful?