Which keyword is used to stop the loop prematurely?
- break
- continue
- exit
- return
The keyword used to stop a loop prematurely in JavaScript is "break." When "break" is encountered within a loop, it immediately exits the loop, even if the loop condition is still true or there are more iterations remaining. This is useful for early termination of a loop based on a specific condition. "continue" skips the current iteration and moves to the next one, while "exit" and "return" have different purposes and are not used for loop control.
Loading...
Related Quiz
- The method myArray.find(callback) returns _______ if no element passes the test.
- Which method would you use to replace an HTML element with another?
- Arrow functions are not suitable for defining _________ functions.
- In a performance-critical application, minimizing the reshuffling of array elements is vital. What method might be avoided when removing elements due to its time complexity?
- The method getElementById selects an element using its ______.