JavaScript Control Flow Quiz

Test your understanding of Javascript Control Flow

JavaScript Quiz #07 - Understanding Control Flow in JavaScript

5 mins read

1. What is the output?

for (let i = 0; i <= 5; i++) {
if (i === 3) {
continue;
}
console.log(i);
}

2. What is the output?

let i = 0;
do {
console.log(i);
i++;
} while (i < 3);

3. What is the output?

const value = null || "Default";
console.log(value);

4. What is the output?

 let num = 5;
const result = num && "Value exists";
console.log(result);

5. What is the output?

 let num = 3;
while (num > 0) {
console.log(num);
num -= 2;
}

6. What is the output?

 const value = "" || 0 || false || "Fallback";
console.log(value);

7. What is the output?

const a = 5;

function foo() {
if (a === 5) {
let a = 10;
}
console.log(a);
}

foo();

8. What is the output?

let x = 0;
while (x < 10) {
if (x === 5) {
break;
}
x++;
}
console.log(x);

9. What is the output?

let x = 2;
let result = '';
switch (x) {
case 1:
result += 'A';
case 2:
result += 'B';
case 3:
result += 'C';
default:
result += 'D';
}
console.log(result);