0
0
Javascriptprogramming~20 mins

Break statement in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Break Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code using break in a loop?
Look at the code below. What will it print to the console?
Javascript
let result = '';
for (let i = 0; i < 5; i++) {
  if (i === 3) {
    break;
  }
  result += i;
}
console.log(result);
A"012"
B"01234"
C"123"
D"0123"
Attempts:
2 left
💡 Hint
Remember, break stops the loop immediately when the condition is met.
Predict Output
intermediate
2:00remaining
What happens when break is inside a nested loop?
What will this code print to the console?
Javascript
let output = '';
for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 3; j++) {
    if (j === 1) {
      break;
    }
    output += `${i}${j} `;
  }
}
console.log(output.trim());
A"00 01 02 10 11 12 20 21 22"
B"00 01 10 11 20 21"
C"00 10 20"
D"00 10 20 21"
Attempts:
2 left
💡 Hint
Break only stops the inner loop, not the outer one.
Predict Output
advanced
2:00remaining
What is the output when break is used inside a switch statement?
Check the code below. What will it print?
Javascript
const value = 2;
switch (value) {
  case 1:
    console.log('One');
    break;
  case 2:
    console.log('Two');
    break;
  case 3:
    console.log('Three');
    break;
  default:
    console.log('Default');
}
A"Two\nThree"
B"Two"
C"One\nTwo"
D"One\nTwo\nThree"
Attempts:
2 left
💡 Hint
Remember that break stops the switch from continuing to the next cases.
Predict Output
advanced
2:00remaining
What error does this code raise?
What error will this code cause when run?
Javascript
while (true) {
  if (false) {
    break;
  }
  console.log('Looping');
  break;
  break;
}
ASyntaxError
BInfinite loop
CTypeError
DNo error, prints 'Looping' once
Attempts:
2 left
💡 Hint
Multiple break statements in a row are allowed but some may be unreachable.
🧠 Conceptual
expert
2:00remaining
Which option correctly explains break behavior in nested loops?
In JavaScript, what does the break statement do inside nested loops?
ABreak exits only the innermost loop where it is called.
BBreak exits all loops regardless of nesting level.
CBreak exits the outermost loop only.
DBreak pauses the loop but continues after a delay.
Attempts:
2 left
💡 Hint
Think about which loop the break is inside.