Quiz: JavaScript Loops

Test your understanding of JavaScript loops with my research based MCQ quiz that covers for loops, while loops, break/continue, and for...in iteration.

1.

What does the following for loop output?

javascript
1
2
3
for (let i = 1; i <= 3; i++) {
  console.log(i);
}
2.

Which loop guarantees at least one execution, even if the condition is false?

3.

What will this code log to the console?

javascript
1
2
3
4
5
var x = 10;
for (var x = 0; x < 3; x++) {
  console.log(x);
}
console.log(x);
4.

What is the output of the following loop?

javascript
1
2
3
for (let i = 10; i >= 6; i -= 2) {
  console.log(i);
}
5.

What does this loop print?

javascript
1
2
3
4
5
let j = 0;
do {
  console.log(j);
  j++;
} while (j < 2);
6.

What does this nested loop log?

javascript
1
2
3
4
5
6
const grid = [[1, 2], [3, 4]];
for (let i = 0; i < grid.length; i++) {
  for (let j = 0; j < grid[i].length; j++) {
    console.log(grid[i][j]);
  }
}