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
What is the purpose of the following JavaScript statement? let result = x > 0 ? 'Positive' : 'Non-positive';
A). Assigns the value 'Positive' to result if x is greater than 0, otherwise assigns 'Non-positive'
B). Checks if x is greater than 0
C). Prints 'Positive' if x is greater than 0, otherwise prints 'Non-positive'
D). None of the above
What is the purpose of the following JavaScript statement? return result;
A). Exits the current loop or switch statement
B). Skips the current iteration in a loop
C). Exits the current function and returns a value
D). Continues to the next iteration in a loop
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
What will be the output of the following JavaScript code? Code: let x = 7; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }
A). Even
B). Odd
C). 7
D). None of the above
What will be the output of the following JavaScript code? Code: let i = 1; do { console.log(i); i++; } while (i < 3);
A). 1 2 3
B). 1 2 3 4
C). 2 3 4
D). Infinite loop
What is the purpose of the following JavaScript statement? continue;
A). Exits the current loop or switch statement
B). Skips the current iteration in a loop
C). Assigns a value to a variable
D). Continues to the next iteration in a loop
What will be the output of the following JavaScript code? Code: let i = 0; for (; 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 is the purpose of the following JavaScript statement? continue;
A). Exits the current loop or switch statement
B). Skips the current iteration in a loop
C). Assigns a value to a variable
D). Continues to the next iteration in a loop