This section covers the questions for Control Flow to clear all your concepts.
Question 1
Which of the following is NOT a valid conditional statement in JavaScript?
if
else if
switch
elseif
Question 2
Which loop always executes at least once, even if the condition is false?
for
while
do...while
for...in
Question 3
What is the role of break keyword inside a loop?
Restart the loop
Move out of the loop
Ignore the rest of the statements below it and continue the loop
None of the above
Question 4
What will the following code output?
for (let i = 0; i < 3; i++) {
if (i === 1) break;
console.log(i);
}
0, 1, 2
0
1
0, 1
Question 5
What will be the output of the following code snippet?
let data = 7
while(data>=0){
if (data<=5){
data--;
continue;
}
console.log(data);
data--;
}
7 6 5 4 3 2 1 0
7 6 5
7 6
0 1 2 3 4 5
Question 6
What will be the output for the following code snippet?
let i = 5;
while (true) {
console.log(i);
i += 5;
if (i > 30) {
break;
}
}
Infinite loop
5 10 15 20 25 30
5 10 15 20 25
5 10 15 20 25 30 35
Question 7
What is the purpose of the 'continue' statement in a loop?
To exit the loop completely
To skip the rest of the code and proceed with the next iteration
To pause the loop temporarily
To repeat the current iteration
Question 8
What is the purpose of the try block in JavaScript?
To define a block of code to test for errors
To throw an error
To handle errors that cannot be caught
To execute code after an error
Question 9
Which statement is used to throw a custom error in JavaScript?
throw
error
catch
raise
Question 10
What is the correct syntax for labeling a loop in JavaScript?
labelName: for(...) {}
for labelName: {}
loop: {...}
label: { for(...) }
There are 10 questions to complete.