Q
What is the purpose of the following JavaScript statement? break;

Answer & Solution

Answer: Option B
Solution:
The break; statement is used to exit the current loop or switch statement. When encountered, it immediately terminates the loop or switch block, and the program continues with the next statement after the loop or switch.
Related Questions on Average

Which of the following JavaScript statements is used to execute a block of code repeatedly until a specified condition becomes false?

A). Function declaration statement

B). Conditional statement (if statement)

C). Assignment statement

D). Looping statement (do-while loop)

What does the following JavaScript code snippet do? Code: let x = 5; while (x > 0) { console.log(x); x -= 1; }

A). Prints even numbers from 5 to 1

B). Prints odd numbers from 5 to 1

C). Prints numbers from 5 to 0

D). Infinite loop

What will be the output of the following JavaScript code? Code: for (let i = 0; i <= 3; i++) { console.log(i); }

A). 0 1 2 3

B). 0 1 2

C). 1 2 3

D). 1 2 3 4

What will be the output of the following JavaScript code? Code: let nums = [1, 2, 3, 4, 5]; for (let n of nums) { if (n % 2 === 0) { console.log(n); } }

A). 1 3 5

B). 2 4 6

C). 1 2 3 4 5

D). 2 4

What does the following JavaScript code snippet do? Code: let numbers = [1, 2, 3, 4, 5]; let sum = 0; for (let num of numbers) { sum += num; } console.log(sum);

A). Finds the maximum number in the array numbers

B). Calculates the average of numbers in the array numbers

C). Sums all numbers in the array numbers

D). Checks if all numbers in the array numbers are even

What does the following JavaScript code snippet do? Code: let num = 5; while (num > 0) { console.log(num); num--; }

A). Declares a variable and assigns a value to it

B). Executes a block of code repeatedly until a condition becomes false

C). Calculates the sum of numbers from 1 to 5

D). Checks if a number is positive or negative

What is the purpose of the following JavaScript statement? break;

A). Assigns a value to a variable

B). Exits the current loop or switch statement

C). Skips the current iteration in a loop

D). Continues to the next iteration in a loop

Which of the following JavaScript statements is used to execute different code based on a specified condition?

A). Function declaration statement

B). Assignment statement

C). Conditional statement (if statement)

D). Looping statement (for loop)

What does the following JavaScript code snippet do? Code: let x = 10; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). Checks if x is even and prints 'Even'

B). Checks if x is odd and prints 'Odd'

C). Checks if x is greater than 0 and prints 'Positive'

D). Checks if x is less than 0 and prints 'Negative'

What will be the output of the following JavaScript code? Code: let x = 15; if (x > 10) { console.log('x is greater than 10'); } else { console.log('x is not greater than 10'); }

A). x is greater than 10

B). x is not greater than 10

C). Undefined

D). Error