FrontendDeveloper.in

JavaScript question detail

What are break and continue statements

The break statement is used to "jump out" of a loop. i.e, It breaks the loop and continues executing the code after the loop.

for (i = 0; i < 10; i++) {
if (i === 5) {
break;
}
text += "Number: " + i + "
";
}

The continue statement is used to "jump over" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.

for (i = 0; i < 10; i++) {
if (i === 5) {
continue;
}
text += "Number: " + i + "
";
}
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399